|
@@ -4,8 +4,13 @@ import { BaseCacheBuilder } from '@box/common/cache/cache-builder';
|
|
|
import { RedisService } from '@box/db/redis/redis.service';
|
|
import { RedisService } from '@box/db/redis/redis.service';
|
|
|
import { MongoPrismaService } from '@box/db/prisma/mongo-prisma.service';
|
|
import { MongoPrismaService } from '@box/db/prisma/mongo-prisma.service';
|
|
|
import { CacheKeys } from '@box/common/cache/cache-keys';
|
|
import { CacheKeys } from '@box/common/cache/cache-keys';
|
|
|
|
|
+import { CacheKeys } from '@box/common/cache/cache-keys';
|
|
|
import { tsCacheKeys } from '@box/common/cache/ts-cache-key.provider';
|
|
import { tsCacheKeys } from '@box/common/cache/ts-cache-key.provider';
|
|
|
import {
|
|
import {
|
|
|
|
|
+ RawVideoPayloadRow,
|
|
|
|
|
+ toVideoPayload,
|
|
|
|
|
+} from '@box/common/cache/video-cache.utils';
|
|
|
|
|
+import {
|
|
|
VideoCacheHelper,
|
|
VideoCacheHelper,
|
|
|
type TagMetadata,
|
|
type TagMetadata,
|
|
|
} from '@box/common/cache/video-cache.helper';
|
|
} from '@box/common/cache/video-cache.helper';
|
|
@@ -16,24 +21,6 @@ import {
|
|
|
*/
|
|
*/
|
|
|
export interface TagMetadataPayload extends TagMetadata {}
|
|
export interface TagMetadataPayload extends TagMetadata {}
|
|
|
|
|
|
|
|
-interface VideoPayloadRow {
|
|
|
|
|
- id: string;
|
|
|
|
|
- title: string;
|
|
|
|
|
- coverImg: string;
|
|
|
|
|
- coverImgNew: string;
|
|
|
|
|
- videoTime: number;
|
|
|
|
|
- country: string;
|
|
|
|
|
- firstTag: string;
|
|
|
|
|
- secondTags: string[];
|
|
|
|
|
- preFileName: string;
|
|
|
|
|
- desc: string;
|
|
|
|
|
- size: bigint;
|
|
|
|
|
- updatedAt: Date;
|
|
|
|
|
- filename: string;
|
|
|
|
|
- fieldNameFs: string;
|
|
|
|
|
- ext: string;
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
/**
|
|
/**
|
|
|
* Cache builder for video category/tag lists following new semantics.
|
|
* Cache builder for video category/tag lists following new semantics.
|
|
|
*
|
|
*
|
|
@@ -443,7 +430,7 @@ export class VideoCategoryCacheBuilder extends BaseCacheBuilder {
|
|
|
|
|
|
|
|
private async fetchVideosForCategory(
|
|
private async fetchVideosForCategory(
|
|
|
categoryId: string,
|
|
categoryId: string,
|
|
|
- ): Promise<VideoPayloadRow[]> {
|
|
|
|
|
|
|
+ ): Promise<RawVideoPayloadRow[]> {
|
|
|
return this.mongoPrisma.videoMedia.findMany({
|
|
return this.mongoPrisma.videoMedia.findMany({
|
|
|
where: {
|
|
where: {
|
|
|
categoryIds: { has: categoryId },
|
|
categoryIds: { has: categoryId },
|
|
@@ -473,7 +460,7 @@ export class VideoCategoryCacheBuilder extends BaseCacheBuilder {
|
|
|
private async fetchVideosForTag(
|
|
private async fetchVideosForTag(
|
|
|
categoryId: string,
|
|
categoryId: string,
|
|
|
tagId: string,
|
|
tagId: string,
|
|
|
- ): Promise<VideoPayloadRow[]> {
|
|
|
|
|
|
|
+ ): Promise<RawVideoPayloadRow[]> {
|
|
|
return this.mongoPrisma.videoMedia.findMany({
|
|
return this.mongoPrisma.videoMedia.findMany({
|
|
|
where: {
|
|
where: {
|
|
|
categoryIds: { has: categoryId },
|
|
categoryIds: { has: categoryId },
|
|
@@ -501,7 +488,7 @@ export class VideoCategoryCacheBuilder extends BaseCacheBuilder {
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private async fetchVideoById(videoId: string): Promise<VideoPayloadRow | null> {
|
|
|
|
|
|
|
+ private async fetchVideoById(videoId: string): Promise<RawVideoPayloadRow | null> {
|
|
|
return this.mongoPrisma.videoMedia.findUnique({
|
|
return this.mongoPrisma.videoMedia.findUnique({
|
|
|
where: { id: videoId },
|
|
where: { id: videoId },
|
|
|
select: {
|
|
select: {
|
|
@@ -524,34 +511,14 @@ export class VideoCategoryCacheBuilder extends BaseCacheBuilder {
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private async writeVideoPayloads(videos: VideoPayloadRow[]): Promise<void> {
|
|
|
|
|
|
|
+ private async writeVideoPayloads(videos: RawVideoPayloadRow[]): Promise<void> {
|
|
|
if (!videos.length) return;
|
|
if (!videos.length) return;
|
|
|
|
|
|
|
|
const entries = videos.map((video) => ({
|
|
const entries = videos.map((video) => ({
|
|
|
key: CacheKeys.appVideoPayloadKey(video.id),
|
|
key: CacheKeys.appVideoPayloadKey(video.id),
|
|
|
- value: this.mapToPayload(video),
|
|
|
|
|
|
|
+ value: toVideoPayload(video),
|
|
|
}));
|
|
}));
|
|
|
|
|
|
|
|
await this.redis.pipelineSetJson(entries);
|
|
await this.redis.pipelineSetJson(entries);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- private mapToPayload(video: VideoPayloadRow) {
|
|
|
|
|
- return {
|
|
|
|
|
- id: video.id,
|
|
|
|
|
- title: video.title,
|
|
|
|
|
- coverImg: video.coverImg,
|
|
|
|
|
- coverImgNew: video.coverImgNew,
|
|
|
|
|
- videoTime: video.videoTime,
|
|
|
|
|
- country: video.country,
|
|
|
|
|
- firstTag: video.firstTag,
|
|
|
|
|
- secondTags: video.secondTags,
|
|
|
|
|
- preFileName: video.preFileName,
|
|
|
|
|
- desc: video.desc,
|
|
|
|
|
- size: video.size,
|
|
|
|
|
- updatedAt: video.updatedAt.toISOString(),
|
|
|
|
|
- filename: video.filename,
|
|
|
|
|
- fieldNameFs: video.fieldNameFs,
|
|
|
|
|
- ext: video.ext,
|
|
|
|
|
- };
|
|
|
|
|
- }
|
|
|
|
|
}
|
|
}
|