Skip to content

Commit 8de7f50

Browse files
committed
fix(profile-updated): cron select only distinct user profiles
1 parent 4823fcc commit 8de7f50

File tree

1 file changed

+7
-13
lines changed

1 file changed

+7
-13
lines changed

src/cron/userProfileUpdatedSync.ts

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { subHours } from 'date-fns';
22
import { Cron } from './cron';
33
import { UserExperience } from '../entity/user/experiences/UserExperience';
4-
import { In, MoreThan } from 'typeorm';
4+
import { In } from 'typeorm';
55
import { processStream } from '../common/streaming';
66
import { logger } from '../logger';
77
import { getSecondsTimestamp, triggerTypedEvent } from '../common';
@@ -39,18 +39,12 @@ export const userProfileUpdatedSync: Cron = {
3939
const userExperiences = await queryReadReplica(
4040
con,
4141
async ({ queryRunner }) => {
42-
const changedUserProfiles: Pick<UserExperience, 'userId'>[] =
43-
await queryRunner.manager.getRepository(UserExperience).find({
44-
select: ['userId'],
45-
where: {
46-
updatedAt: MoreThan(timeThreshold),
47-
},
48-
relations: {
49-
skills: true,
50-
company: true,
51-
location: true,
52-
},
53-
});
42+
const changedUserProfiles = await queryRunner.manager
43+
.getRepository(UserExperience)
44+
.createQueryBuilder()
45+
.select('DISTINCT "userId"', 'userId')
46+
.where('"updatedAt" > :timeThreshold', { timeThreshold })
47+
.getRawMany<{ userId: string }>();
5448

5549
// get all experiences for the changed user profiles so we can send full profile updates
5650
const userExperiences = await queryReadReplica(

0 commit comments

Comments
 (0)