Skip to content
This repository has been archived by the owner on Oct 11, 2022. It is now read-only.

Commit

Permalink
Merge pull request #2699 from tomwhale/only-update-lastSeen-if-later
Browse files Browse the repository at this point in the history
#2645: Only update the threadLastSeen if its later than the current one
  • Loading branch information
brianlovin authored Apr 4, 2018
2 parents a146337 + f46920b commit a26d014
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
15 changes: 14 additions & 1 deletion athena/queues/track-user-thread-last-seen.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
createUserThread,
} from '../models/usersThreads';
import type { Job, UserThreadLastSeenJobData } from 'shared/bull/types';
import type { DBUsersThreads } from 'shared/types';

export default async (job: Job<UserThreadLastSeenJobData>) => {
const { userId, threadId, timestamp } = job.data;
Expand All @@ -26,9 +27,21 @@ export default async (job: Job<UserThreadLastSeenJobData>) => {
).toString()}`
);

const record = await getUsersThread(userId, threadId);
const record: ?DBUsersThreads = await getUsersThread(userId, threadId);

if (record) {
if (
record.lastSeen &&
new Date(record.lastSeen).getTime() > new Date(date).getTime()
) {
debug(
`old lastSeen ${record.lastSeen.toString()} is later than new lastSeen ${date.toString()}, not running job:\nuserId: ${userId}\nthreadId: ${threadId}\ntimestamp: ${new Date(
timestamp
).toString()}`
);
return;
}

debug(
`existing usersThread, updating usersThreads#${record.id} with lastSeen`
);
Expand Down
1 change: 1 addition & 0 deletions shared/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ export type DBUsersThreads = {
receiveNotifications: boolean,
threadId: string,
userId: string,
lastSeen?: Date | number,
};

export type SearchThread = {
Expand Down

0 comments on commit a26d014

Please sign in to comment.