From 8d2f1a51068dffdae2f194f3f715bc8e9a601ec2 Mon Sep 17 00:00:00 2001 From: Ramin Date: Thu, 20 Jun 2024 02:24:03 +0330 Subject: [PATCH 1/5] remove unused fields from logs --- .../checkProjectVerificationStatus.ts | 52 +++---------------- 1 file changed, 8 insertions(+), 44 deletions(-) diff --git a/src/services/cronJobs/checkProjectVerificationStatus.ts b/src/services/cronJobs/checkProjectVerificationStatus.ts index d4cde104a..f23fe1698 100644 --- a/src/services/cronJobs/checkProjectVerificationStatus.ts +++ b/src/services/cronJobs/checkProjectVerificationStatus.ts @@ -1,19 +1,11 @@ import { schedule } from 'node-cron'; import moment = require('moment'); import { Project, RevokeSteps } from '../../entities/project'; -import { HISTORY_DESCRIPTIONS } from '../../entities/projectStatusHistory'; import config from '../../config'; import { logger } from '../../utils/logger'; import { projectsWithoutUpdateAfterTimeFrame } from '../../repositories/projectRepository'; import { i18n, translationErrorMessagesKeys } from '../../utils/errorMessages'; -import { makeFormDraft } from '../../repositories/projectVerificationRepository'; -import { sleep } from '../../utils/utils'; import { getNotificationAdapter } from '../../adapters/adaptersFactory'; -import { refreshUserProjectPowerView } from '../../repositories/userProjectPowerViewRepository'; -import { - refreshProjectFuturePowerView, - refreshProjectPowerView, -} from '../../repositories/projectPowerViewRepository'; const cronJobTime = (config.get( @@ -60,7 +52,6 @@ export const checkProjectVerificationStatus = async () => { maxDaysForSendingUpdateWarning, ); logger.debug('checkProjectVerificationStatus() has been called', { - maxDaysForSendingUpdateWarning, foundProjectsCount: projects.length, projects: projects.map(p => { return { @@ -76,29 +67,25 @@ export const checkProjectVerificationStatus = async () => { } catch (error) { logger.error('Error in remindUpdatesOrRevokeVerification', { projectId: project.id, - projectSlug: project.slug, projectVerificationStatus: project.verificationStatus, error, }); } } - - if (projects.length > 0) { - await Promise.all([ - refreshUserProjectPowerView(), - refreshProjectPowerView(), - refreshProjectFuturePowerView(), - ]); - } }; const remindUpdatesOrRevokeVerification = async (project: Project) => { // We don't revoke verification badge for any projects. - const latestUpdate = - project.projectUpdates?.[0].createdAt || project.updatedAt; + if ( + !project || + !project.projectUpdates || + project.projectUpdates.length === 0 + ) { + return; + } + const latestUpdate = project.projectUpdates[0].createdAt; logger.debug('remindUpdatesOrRevokeVerification() has been called', { projectId: project.id, - projectSlug: project.slug, projectVerificationStatus: project.verificationStatus, latestUpdate, }); @@ -127,31 +114,9 @@ const remindUpdatesOrRevokeVerification = async (project: Project) => { await sendProperNotification(project, project.verificationStatus as string); logger.debug('remindUpdatesOrRevokeVerification() save project', { projectId: project.id, - slug: project.slug, verificationStatus: project.verificationStatus, }); } - - // draft the verification form to allow to reapply - if ( - project.projectVerificationForm && - project.verificationStatus === RevokeSteps.Revoked - ) { - await makeFormDraft({ - formId: project.projectVerificationForm.id, - }); - } - - // save status changes history - if (project.verificationStatus === RevokeSteps.Revoked) { - await Project.addProjectStatusHistoryRecord({ - project, - status: project.status, - description: HISTORY_DESCRIPTIONS.CHANGED_TO_UNVERIFIED_BY_CRONJOB, - }); - } - - await sleep(300); }; const sendProperNotification = ( @@ -160,7 +125,6 @@ const sendProperNotification = ( ) => { logger.debug('sendProperNotification()', { projectId: project.id, - slug: project.slug, verificationStatus: project.verificationStatus, }); switch (projectVerificationStatus) { From 0f9717f491006216e6c7d48a112e059aa774b9d8 Mon Sep 17 00:00:00 2001 From: Ramin Date: Thu, 20 Jun 2024 02:25:13 +0330 Subject: [PATCH 2/5] remove user from badge warning --- .../notifications/NotificationCenterAdapter.ts | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/adapters/notifications/NotificationCenterAdapter.ts b/src/adapters/notifications/NotificationCenterAdapter.ts index 884ef7e92..b0b120b0e 100644 --- a/src/adapters/notifications/NotificationCenterAdapter.ts +++ b/src/adapters/notifications/NotificationCenterAdapter.ts @@ -373,7 +373,7 @@ export class NotificationCenterAdapter implements NotificationAdapterInterface { }, trackId: `project-badge-revoked-${ project.id - }-${user.walletAddress?.toLowerCase()}-${now}`, + }-${user?.walletAddress?.toLowerCase()}-${now}`, }); } @@ -394,13 +394,15 @@ export class NotificationCenterAdapter implements NotificationAdapterInterface { }, trackId: `project-badge-revoke-reminder-${ project.id - }-${user.walletAddress?.toLowerCase()}-${now}`, + }-${user?.walletAddress?.toLowerCase()}-${now}`, }); } async projectBadgeRevokeWarning(params: { project: Project }): Promise { const { project } = params; - const user = project.adminUser as User; + if (!project.adminUser?.email) { + project.adminUser = (await findUserById(project.adminUserId))!; + } const now = new Date(); await sendProjectRelatedNotificationsQueue.add({ @@ -414,7 +416,7 @@ export class NotificationCenterAdapter implements NotificationAdapterInterface { }, trackId: `project-badge-revoke-warning-${ project.id - }-${user.walletAddress?.toLowerCase()}-${now}`, + }-${project.adminUser.walletAddress?.toLowerCase()}-${now}`, }); } @@ -422,7 +424,9 @@ export class NotificationCenterAdapter implements NotificationAdapterInterface { project: Project; }): Promise { const { project } = params; - const user = project.adminUser as User; + if (!project.adminUser?.email) { + project.adminUser = (await findUserById(project.adminUserId))!; + } const now = Date.now(); await sendProjectRelatedNotificationsQueue.add({ project, @@ -435,7 +439,7 @@ export class NotificationCenterAdapter implements NotificationAdapterInterface { }, trackId: `project-badge-revoke-last-warning-${ project.id - }-${user.walletAddress?.toLowerCase()}-${now}`, + }-${project.adminUser?.walletAddress?.toLowerCase()}-${now}`, }); } @@ -455,7 +459,7 @@ export class NotificationCenterAdapter implements NotificationAdapterInterface { }, trackId: `project-badge-up-for-revoking-${ project.id - }-${user.walletAddress?.toLowerCase()}-${now}`, + }-${user?.walletAddress?.toLowerCase()}-${now}`, }); } From 713eca007b1adca2a2cc1c86d97d6fecafb2e35a Mon Sep 17 00:00:00 2001 From: Ramin Date: Thu, 20 Jun 2024 02:27:04 +0330 Subject: [PATCH 3/5] optimize projectsWithoutUpdateAfterTimeFrame --- src/repositories/projectRepository.ts | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/src/repositories/projectRepository.ts b/src/repositories/projectRepository.ts index 48f2f9315..07c99b3c7 100644 --- a/src/repositories/projectRepository.ts +++ b/src/repositories/projectRepository.ts @@ -258,6 +258,14 @@ export const projectsWithoutUpdateAfterTimeFrame = async ( .leftJoin('project.projectUpdates', 'projectUpdates') .select('project.id', 'projectId') .addSelect('MAX(projectUpdates.createdAt)', 'latestUpdate') + .where('project.isImported = false') + .andWhere('project.verified = true') + .andWhere( + '(project.verificationStatus NOT IN (:...statuses) OR project.verificationStatus IS NULL)', + { + statuses: [RevokeSteps.UpForRevoking, RevokeSteps.Revoked], + }, + ) .groupBy('project.id') .having('MAX(projectUpdates.createdAt) < :date', { date }) .getRawMany(); @@ -267,21 +275,9 @@ export const projectsWithoutUpdateAfterTimeFrame = async ( ); const projects = await Project.createQueryBuilder('project') - .where('project.isImported = false') - .andWhere('project.verified = true') - .andWhere( - '(project.verificationStatus NOT IN (:...statuses) OR project.verificationStatus IS NULL)', - { - statuses: [RevokeSteps.UpForRevoking, RevokeSteps.Revoked], - }, - ) - .andWhereInIds(validProjectIds) - .leftJoinAndSelect( - 'project.projectVerificationForm', - 'projectVerificationForm', - ) - .leftJoinAndSelect('project.adminUser', 'user') - .leftJoinAndSelect('project.projectUpdates', 'projectUpdates') + .whereInIds(validProjectIds) + .leftJoin('project.projectUpdates', 'projectUpdates') + .addSelect('projectUpdates.createdAt') .getMany(); projects.forEach(project => { From 117f6b7824b2c0b0feaa02d60b6134e5f96ceb61 Mon Sep 17 00:00:00 2001 From: Ramin Date: Thu, 20 Jun 2024 18:03:50 +0330 Subject: [PATCH 4/5] add projectId to projectRepository.ts --- src/repositories/projectRepository.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/repositories/projectRepository.ts b/src/repositories/projectRepository.ts index 07c99b3c7..7b09d7da6 100644 --- a/src/repositories/projectRepository.ts +++ b/src/repositories/projectRepository.ts @@ -277,7 +277,7 @@ export const projectsWithoutUpdateAfterTimeFrame = async ( const projects = await Project.createQueryBuilder('project') .whereInIds(validProjectIds) .leftJoin('project.projectUpdates', 'projectUpdates') - .addSelect('projectUpdates.createdAt') + .addSelect(['projectUpdates.createdAt', 'projectUpdates.id']) .getMany(); projects.forEach(project => { From 851d41133b0394a150c279d1dc65dc3576e8400a Mon Sep 17 00:00:00 2001 From: Ramin Date: Thu, 20 Jun 2024 18:06:59 +0330 Subject: [PATCH 5/5] remove unnecessary updatedAt --- .../cronJobs/checkProjectVerificationStatus.test.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/services/cronJobs/checkProjectVerificationStatus.test.ts b/src/services/cronJobs/checkProjectVerificationStatus.test.ts index 9929effbf..379a7583b 100644 --- a/src/services/cronJobs/checkProjectVerificationStatus.test.ts +++ b/src/services/cronJobs/checkProjectVerificationStatus.test.ts @@ -25,8 +25,10 @@ function checkProjectVerificationStatusTestCases() { title: String(new Date().getTime()), slug: String(new Date().getTime()), verified: true, - updatedAt: moment().subtract(46, 'days').endOf('day').toDate(), - projectUpdateCreationDate: moment().subtract(46, 'days').endOf('day'), + projectUpdateCreationDate: moment() + .subtract(46, 'days') + .endOf('day') + .toDate(), verificationStatus: RevokeSteps.Reminder, }); @@ -46,7 +48,6 @@ function checkProjectVerificationStatusTestCases() { title: String(new Date().getTime()), slug: String(new Date().getTime()), verified: true, - updatedAt: moment().subtract(91, 'days').endOf('day').toDate(), projectUpdateCreationDate: moment().subtract(91, 'days').endOf('day'), verificationStatus: RevokeSteps.Warning, }); @@ -67,7 +68,6 @@ function checkProjectVerificationStatusTestCases() { title: String(new Date().getTime()), slug: String(new Date().getTime()), verified: true, - updatedAt: moment().subtract(105, 'days').endOf('day').toDate(), projectUpdateCreationDate: moment().subtract(105, 'days').endOf('day'), verificationStatus: RevokeSteps.LastChance, });