diff --git a/src/mappings/content/commentsAndReactions.ts b/src/mappings/content/commentsAndReactions.ts index c2b183db9..8b695c614 100644 --- a/src/mappings/content/commentsAndReactions.ts +++ b/src/mappings/content/commentsAndReactions.ts @@ -43,7 +43,6 @@ import { genericEventFields, metaprotocolTransactionFailure, commentCountersManager, - videoRelevanceManager, } from '../utils' import { getChannelOwnerMemberByChannelId } from './utils' @@ -257,8 +256,6 @@ export async function processReactVideoMessage( await processVideoReaction(overlay, block, memberId, video, reactionType, existingReaction) - videoRelevanceManager.scheduleRecalcForVideo(video.id) - return new MetaprotocolTransactionResultOK() } @@ -403,7 +400,6 @@ export async function processCreateCommentMessage( // schedule comment counters update commentCountersManager.scheduleRecalcForComment(comment.parentCommentId) commentCountersManager.scheduleRecalcForVideo(comment.videoId) - videoRelevanceManager.scheduleRecalcForVideo(comment.videoId) // add CommentCreated event const event = overlay.getRepository(Event).new({ @@ -537,7 +533,6 @@ export async function processDeleteCommentMessage( // schedule comment counters update commentCountersManager.scheduleRecalcForComment(comment.parentCommentId) commentCountersManager.scheduleRecalcForVideo(comment.videoId) - videoRelevanceManager.scheduleRecalcForVideo(comment.videoId) // update the comment comment.text = '' diff --git a/src/mappings/content/metadata.ts b/src/mappings/content/metadata.ts index 59d513ea9..deceac00e 100644 --- a/src/mappings/content/metadata.ts +++ b/src/mappings/content/metadata.ts @@ -63,7 +63,6 @@ import { genericEventFields, invalidMetadata, metaprotocolTransactionFailure, - videoRelevanceManager, } from '../utils' import { AsDecoded, ASSETS_MAP, EntityAssetProps, EntityAssetsMap, MetaNumberProps } from './utils' @@ -572,7 +571,6 @@ export async function processModerateCommentMessage( // schedule comment counters updates commentCountersManager.scheduleRecalcForComment(comment.parentCommentId) commentCountersManager.scheduleRecalcForVideo(comment.videoId) - videoRelevanceManager.scheduleRecalcForVideo(comment.videoId) comment.text = '' comment.status = CommentStatus.MODERATED diff --git a/src/mappings/content/video.ts b/src/mappings/content/video.ts index aa73b027d..eb6ebc502 100644 --- a/src/mappings/content/video.ts +++ b/src/mappings/content/video.ts @@ -8,7 +8,7 @@ import { DecodedMetadataObject } from '@joystream/metadata-protobuf/types' import { integrateMeta } from '@joystream/metadata-protobuf/utils' import { Channel, Video, VideoViewEvent } from '../../model' import { EventHandlerContext } from '../../utils/events' -import { deserializeMetadata, u8aToBytes, videoRelevanceManager } from '../utils' +import { deserializeMetadata, u8aToBytes } from '../utils' import { processVideoMetadata } from './metadata' import { deleteVideo, encodeAssets, processAppActionMetadata, processNft } from './utils' import { generateAppActionCommitment } from '@joystream/js/utils' @@ -43,8 +43,6 @@ export async function processVideoCreatedEvent({ videoRelevance: 0, }) - videoRelevanceManager.scheduleRecalcForVideo(videoId) - // fetch related channel and owner const channel = await overlay.getRepository(Channel).getByIdOrFail(channelId.toString()) diff --git a/src/mappings/utils.ts b/src/mappings/utils.ts index 648834573..1b395785f 100644 --- a/src/mappings/utils.ts +++ b/src/mappings/utils.ts @@ -19,7 +19,7 @@ import { VideoRelevanceManager } from '../utils/VideoRelevanceManager' export const commentCountersManager = new CommentCountersManager() export const videoRelevanceManager = new VideoRelevanceManager() -videoRelevanceManager.init(1000 * 60 * 60) +videoRelevanceManager.init(1000 * 60 * 10) export const JOYSTREAM_SS58_PREFIX = 126 diff --git a/src/processor.ts b/src/processor.ts index 76eee94d7..b34f2bdc3 100644 --- a/src/processor.ts +++ b/src/processor.ts @@ -322,7 +322,7 @@ processor.run(new TypeormDatabase({ isolationLevel: 'READ COMMITTED' }), async ( await offchainState.import(em) await commentCountersManager.updateVideoCommentsCounters(em, true) await commentCountersManager.updateParentRepliesCounters(em, true) - await videoRelevanceManager.updateVideoRelevanceValue(em, true) + await videoRelevanceManager.updateVideoRelevanceValue(em) ctx.log.info(`Offchain state successfully imported!`) } } diff --git a/src/server-extension/resolvers/AdminResolver/index.ts b/src/server-extension/resolvers/AdminResolver/index.ts index ba390c7a6..1aa582c32 100644 --- a/src/server-extension/resolvers/AdminResolver/index.ts +++ b/src/server-extension/resolvers/AdminResolver/index.ts @@ -112,7 +112,7 @@ export class AdminResolver { ], em ) - await videoRelevanceManager.updateVideoRelevanceValue(em, true) + await videoRelevanceManager.updateVideoRelevanceValue(em) return { isApplied: true } } diff --git a/src/server-extension/resolvers/AdminResolver/utils.ts b/src/server-extension/resolvers/AdminResolver/utils.ts index b39e331b0..91ac740ab 100644 --- a/src/server-extension/resolvers/AdminResolver/utils.ts +++ b/src/server-extension/resolvers/AdminResolver/utils.ts @@ -1,18 +1,14 @@ import { EntityManager, In } from 'typeorm' import { CommentCountersManager } from '../../../utils/CommentsCountersManager' import { Comment } from '../../../model' -import { VideoRelevanceManager } from '../../../utils/VideoRelevanceManager' export async function processCommentsCensorshipStatusUpdate(em: EntityManager, ids: string[]) { const manager = new CommentCountersManager() - const videoRelevanceManager = new VideoRelevanceManager() const comments = await em.getRepository(Comment).find({ where: { id: In(ids) } }) comments.forEach((c) => { manager.scheduleRecalcForComment(c.parentCommentId) manager.scheduleRecalcForVideo(c.videoId) - videoRelevanceManager.scheduleRecalcForVideo(c.videoId) }) await manager.updateVideoCommentsCounters(em) await manager.updateParentRepliesCounters(em) - await videoRelevanceManager.updateVideoRelevanceValue(em) } diff --git a/src/server-extension/resolvers/VideosResolver/index.ts b/src/server-extension/resolvers/VideosResolver/index.ts index 95886f9e8..706f982c7 100644 --- a/src/server-extension/resolvers/VideosResolver/index.ts +++ b/src/server-extension/resolvers/VideosResolver/index.ts @@ -34,7 +34,6 @@ import { config, ConfigVariable } from '../../../utils/config' import { Context } from '../../check' import { isObject } from 'lodash' import { has } from '../../../utils/misc' -import { videoRelevanceManager } from '../../../mappings/utils' import { uniqueId } from '../../../utils/crypto' import { UserOnly } from '../middleware' @@ -237,12 +236,7 @@ export class VideosResolver { videoId, }) - const tick = await config.get(ConfigVariable.VideoRelevanceViewsTick, em) - if (video.viewsNum % tick === 0) { - videoRelevanceManager.scheduleRecalcForVideo(videoId) - } await em.save([video, video.channel, newView]) - await videoRelevanceManager.updateVideoRelevanceValue(em) return { videoId, viewsNum: video.viewsNum, diff --git a/src/utils/VideoRelevanceManager.ts b/src/utils/VideoRelevanceManager.ts index f67fe99af..c307d0ae9 100644 --- a/src/utils/VideoRelevanceManager.ts +++ b/src/utils/VideoRelevanceManager.ts @@ -6,8 +6,6 @@ import { globalEm } from './globalEm' export const NEWNESS_SECONDS_DIVIDER = 60 * 60 * 24 export class VideoRelevanceManager { - private videosToUpdate: Set = new Set() - init(intervalMs: number): void { this.updateLoop(intervalMs) .then(() => { @@ -19,10 +17,6 @@ export class VideoRelevanceManager { }) } - scheduleRecalcForVideo(id: string | null | undefined) { - id && this.videosToUpdate.add(id) - } - async updateVideoRelevanceValue(em: EntityManager) { const [ newnessWeight, @@ -62,12 +56,11 @@ export class VideoRelevanceManager { GROUP BY channel.id) UPDATE video - SET video_relevance = COALESCE(xd.maxScore, 1) + SET video_relevance = COALESCE(topChannelVideo.maxScore, 1) FROM videos_with_weight as videoCte LEFT JOIN top_channel_score as topChannelVideo on topChannelVideo.channelId = videoCte.cId and topChannelVideo.maxScore = videoCte.videoRelevance WHERE video.id = videoCte.vId; `) - this.videosToUpdate.clear() } private async updateLoop(intervalMs: number): Promise {