|
|
@@ -12,12 +12,14 @@ import {
|
|
|
} from '../../../cache-sync/cache-sync.types';
|
|
|
import { CreateTagDto, ListTagDto, UpdateTagDto } from './tag.dto';
|
|
|
import { CommonStatus } from '../common/status.enum';
|
|
|
+import { CategoryService } from '../category/category.service';
|
|
|
|
|
|
@Injectable()
|
|
|
export class TagService {
|
|
|
constructor(
|
|
|
private readonly mongoPrismaService: MongoPrismaService,
|
|
|
private readonly cacheSyncService: CacheSyncService,
|
|
|
+ private readonly categoryService: CategoryService,
|
|
|
) {}
|
|
|
|
|
|
/**
|
|
|
@@ -32,6 +34,15 @@ export class TagService {
|
|
|
return Date.now();
|
|
|
}
|
|
|
|
|
|
+ private async scheduleCategoryCaches(categoryId: string): Promise<void> {
|
|
|
+ await this.cacheSyncService.scheduleAction({
|
|
|
+ entityType: CacheEntityType.CATEGORY,
|
|
|
+ operation: CacheOperation.REFRESH,
|
|
|
+ payload: { categoryId },
|
|
|
+ });
|
|
|
+ await this.cacheSyncService.scheduleCategoryRefreshAll();
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Ensure category exists.
|
|
|
* NOTE: Categories are no longer tied to channels, so we only validate category existence.
|
|
|
@@ -78,6 +89,12 @@ export class TagService {
|
|
|
},
|
|
|
});
|
|
|
|
|
|
+ await this.categoryService.refreshTagsMetadata(tag.categoryId);
|
|
|
+ await this.scheduleCategoryCaches(tag.categoryId);
|
|
|
+
|
|
|
+ await this.categoryService.refreshTagsMetadata(tag.categoryId);
|
|
|
+ await this.scheduleCategoryCaches(tag.categoryId);
|
|
|
+
|
|
|
// Schedule cache sync actions
|
|
|
await this.cacheSyncService.scheduleAction({
|
|
|
entityType: CacheEntityType.TAG,
|
|
|
@@ -142,15 +159,18 @@ export class TagService {
|
|
|
data,
|
|
|
});
|
|
|
|
|
|
- // Schedule cache sync actions for both old and new category
|
|
|
if (oldCategoryId !== dto.categoryId) {
|
|
|
- // Category changed: refresh both old and new
|
|
|
+ await this.categoryService.ensureTagChildren(oldCategoryId);
|
|
|
+ await this.scheduleCategoryCaches(oldCategoryId);
|
|
|
await this.cacheSyncService.scheduleAction({
|
|
|
entityType: CacheEntityType.TAG,
|
|
|
operation: CacheOperation.REFRESH,
|
|
|
payload: { categoryId: oldCategoryId },
|
|
|
});
|
|
|
}
|
|
|
+ await this.categoryService.refreshTagsMetadata(dto.categoryId);
|
|
|
+ await this.scheduleCategoryCaches(dto.categoryId);
|
|
|
+
|
|
|
await this.cacheSyncService.scheduleAction({
|
|
|
entityType: CacheEntityType.TAG,
|
|
|
operation: CacheOperation.REFRESH,
|
|
|
@@ -224,6 +244,9 @@ export class TagService {
|
|
|
try {
|
|
|
await this.mongoPrismaService.tag.delete({ where: { id } });
|
|
|
|
|
|
+ await this.categoryService.ensureTagChildren(categoryId);
|
|
|
+ await this.scheduleCategoryCaches(categoryId);
|
|
|
+
|
|
|
// Schedule cache sync actions
|
|
|
await this.cacheSyncService.scheduleAction({
|
|
|
entityType: CacheEntityType.TAG,
|