| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- import { Injectable } from '@nestjs/common';
- import { BaseCacheBuilder } from '@box/common/cache/cache-builder';
- import { tsCacheKeys } from '@box/common/cache/ts-cache-key.provider';
- import { RedisService } from '@box/db/redis/redis.service';
- import { MongoPrismaService } from '@box/db/prisma/mongo-prisma.service';
- export interface ChannelCachePayload {
- // id: string;
- channelId: string;
- // name: string;
- landingUrl: string;
- videoCdn?: string;
- coverCdn?: string;
- clientName?: string;
- clientNotice?: string;
- // remark?: string;
- }
- @Injectable()
- export class ChannelCacheBuilder extends BaseCacheBuilder {
- constructor(redis: RedisService, mongoPrisma: MongoPrismaService) {
- super(redis, mongoPrisma, ChannelCacheBuilder.name);
- }
- async buildAll(): Promise<void> {
- const channels = await this.mongoPrisma.channel.findMany({
- orderBy: [{ name: 'asc' }],
- });
- const payloads: ChannelCachePayload[] = channels.map((channel) => ({
- // id: channel.id,
- channelId: channel.channelId,
- // name: channel.name,
- landingUrl: channel.landingUrl,
- videoCdn: channel.videoCdn ?? undefined,
- coverCdn: channel.coverCdn ?? undefined,
- clientName: channel.clientName ?? undefined,
- clientNotice: channel.clientNotice ?? undefined,
- // remark: channel.remark ?? undefined,
- }));
- const entries: Array<{ key: string; value: unknown }> = payloads.map(
- (payload) => ({
- key: tsCacheKeys.channel.byId(payload.channelId),
- value: payload,
- }),
- );
- entries.push({ key: tsCacheKeys.channel.all(), value: payloads });
- await this.redis.pipelineSetJson(entries);
- this.logger.log(`Built ${payloads.length} channels`);
- }
- }
|