mirror of
https://github.com/docmost/docmost.git
synced 2026-05-17 23:14:07 +08:00
feat: labels (WIP)
This commit is contained in:
@@ -48,6 +48,7 @@ import { EventEmitter2 } from '@nestjs/event-emitter';
|
||||
import { CollaborationGateway } from '../../../collaboration/collaboration.gateway';
|
||||
import { markdownToHtml } from '@docmost/editor-ext';
|
||||
import { WatcherService } from '../../watcher/watcher.service';
|
||||
import { LabelRepo } from '@docmost/db/repos/label/label.repo';
|
||||
|
||||
@Injectable()
|
||||
export class PageService {
|
||||
@@ -64,6 +65,7 @@ export class PageService {
|
||||
private eventEmitter: EventEmitter2,
|
||||
private collaborationGateway: CollaborationGateway,
|
||||
private readonly watcherService: WatcherService,
|
||||
private readonly labelRepo: LabelRepo,
|
||||
) {}
|
||||
|
||||
async findById(
|
||||
@@ -729,11 +731,18 @@ export class PageService {
|
||||
}
|
||||
|
||||
if (pageIds.length > 0) {
|
||||
const affectedLabelIds =
|
||||
await this.labelRepo.findLabelIdsByPageIds(pageIds);
|
||||
|
||||
await this.db.deleteFrom('pages').where('id', 'in', pageIds).execute();
|
||||
this.eventEmitter.emit(EventName.PAGE_DELETED, {
|
||||
pageIds: pageIds,
|
||||
workspaceId,
|
||||
});
|
||||
|
||||
if (affectedLabelIds.length > 0) {
|
||||
await this.labelRepo.deleteOrphanedLabels(affectedLabelIds);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import { KyselyDB } from '@docmost/db/types/kysely.types';
|
||||
import { InjectQueue } from '@nestjs/bullmq';
|
||||
import { Queue } from 'bullmq';
|
||||
import { QueueJob, QueueName } from '../../../integrations/queue/constants';
|
||||
import { LabelRepo } from '@docmost/db/repos/label/label.repo';
|
||||
|
||||
@Injectable()
|
||||
export class TrashCleanupService {
|
||||
@@ -14,6 +15,7 @@ export class TrashCleanupService {
|
||||
constructor(
|
||||
@InjectKysely() private readonly db: KyselyDB,
|
||||
@InjectQueue(QueueName.ATTACHMENT_QUEUE) private attachmentQueue: Queue,
|
||||
private readonly labelRepo: LabelRepo,
|
||||
) {}
|
||||
|
||||
@Interval('trash-cleanup', 24 * 60 * 60 * 1000) // every 24 hours
|
||||
@@ -104,7 +106,14 @@ export class TrashCleanupService {
|
||||
|
||||
try {
|
||||
if (pageIds.length > 0) {
|
||||
const affectedLabelIds =
|
||||
await this.labelRepo.findLabelIdsByPageIds(pageIds);
|
||||
|
||||
await this.db.deleteFrom('pages').where('id', 'in', pageIds).execute();
|
||||
|
||||
if (affectedLabelIds.length > 0) {
|
||||
await this.labelRepo.deleteOrphanedLabels(affectedLabelIds);
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
// Log but don't throw - pages might have been deleted by another node
|
||||
|
||||
Reference in New Issue
Block a user