This repository was archived by the owner on Oct 11, 2022. It is now read-only.
-
Couldn't load subscription status.
- Fork 1.2k
Frecency thread feeds (second try) #3798
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
f048d8b
WIP: Assign each thread a score
mxstbr 33e35ca
Add calculateThreadScore jobs to the queue from mutations
mxstbr c47cafc
Add calculate thread score job if threadScoreUPdatedAt is older than …
mxstbr 34a1443
Store thread.scoreUpdatedAt
mxstbr dc6bd72
Fix ms in a day
mxstbr d7beed4
Fix flow types
mxstbr 2578572
Aggressively decay based on lastActive
mxstbr 1bd214a
Fix typo
mxstbr b119225
Add sort arg to Community.threadConnection
mxstbr cc4c6b4
Run calculateThreadScore once for each thread
mxstbr d01c9ae
Rework thread trending score algorithm with exponential explosion
mxstbr b073fd6
Remove not-working migration
mxstbr 4f3ed40
Top => trending
mxstbr ea79472
Make sure it is distinct participants
mxstbr c3f3d17
threadConnection sort arg lowercase
mxstbr eea3984
Make sure new threads get scores if they dont have any
mxstbr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,109 @@ | ||
| // @flow | ||
| const { db } = require('./db'); | ||
| import type { DBThread } from 'shared/types'; | ||
|
|
||
| export const getThread = (id: string): Promise<Object> => { | ||
| export const getThread = (id: string): Promise<DBThread> => { | ||
| return db | ||
| .table('threads') | ||
| .get(id) | ||
| .run(); | ||
| }; | ||
|
|
||
| export const getParticipantCount = (threadId: string): Promise<number> => { | ||
| return db | ||
| .table('usersThreads') | ||
| .getAll(threadId, { index: 'threadId' }) | ||
| .filter({ isParticipant: true }) | ||
| .count() | ||
| .default(0) | ||
| .run(); | ||
| }; | ||
|
|
||
| const timeRanges = { | ||
| hourly: { start: 3600, end: 0 }, | ||
| daily: { start: 86400, end: 3600 }, | ||
| weekly: { start: 604800, end: 86400 }, | ||
| rest: { start: Date.now(), end: 604800 }, | ||
| }; | ||
|
|
||
| export const getParticipantCountByTime = ( | ||
| threadId: string, | ||
| range: 'hourly' | 'daily' | 'weekly' | 'rest' | ||
| ): Promise<number> => { | ||
| return db | ||
| .table('messages') | ||
| .getAll(threadId, { index: 'threadId' }) | ||
| .filter( | ||
| db.row | ||
| .hasFields('deletedAt') | ||
| .not() | ||
| .and( | ||
| db | ||
| .row('timestamp') | ||
| .ge(db.now().sub(timeRanges[range].start)) | ||
| .and(db.row('timestamp').le(db.now().sub(timeRanges[range].end))) | ||
| ) | ||
| ) | ||
| .map(rec => rec('senderId')) | ||
| .distinct() | ||
| .count() | ||
| .default(0) | ||
| .run(); | ||
| }; | ||
|
|
||
| export const getReactionCountByTime = ( | ||
| threadId: string, | ||
| range: 'hourly' | 'daily' | 'weekly' | 'rest' | ||
| ): Promise<number> => { | ||
| return db | ||
| .table('threadReactions') | ||
| .getAll(threadId, { index: 'threadId' }) | ||
| .filter( | ||
| db.row | ||
| .hasFields('deletedAt') | ||
| .not() | ||
| .and( | ||
| db | ||
| .row('createdAt') | ||
| .ge(db.now().sub(timeRanges[range].start)) | ||
| .and(db.row('createdAt').le(db.now().sub(timeRanges[range].end))) | ||
| ) | ||
| ) | ||
| .count() | ||
| .default(0) | ||
| .run(); | ||
| }; | ||
|
|
||
| export const getMessageCount = (threadId: string): Promise<number> => { | ||
| return db | ||
| .table('messages') | ||
| .getAll(threadId, { index: 'threadId' }) | ||
| .filter(db.row.hasFields('deletedAt').not()) | ||
| .count() | ||
| .default(0) | ||
| .run(); | ||
| }; | ||
|
|
||
| export const getReactionCount = (threadId: string): Promise<number> => { | ||
| return db | ||
| .table('threadReactions') | ||
| .getAll(threadId, { index: 'threadId' }) | ||
| .filter(row => row.hasFields('deletedAt').not()) | ||
| .count() | ||
| .default(0) | ||
| .run(); | ||
| }; | ||
|
|
||
| export const storeThreadScore = ( | ||
| threadId: string, | ||
| score: number | ||
| ): Promise<any> => { | ||
| return db | ||
| .table('threads') | ||
| .get(threadId) | ||
| .update({ | ||
| score, | ||
| scoreUpdatedAt: new Date(), | ||
| }) | ||
| .run(); | ||
| }; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do we want these options to be defined and expand over time? Is trending the same as popular? Can we ever sort by date? e.g. trending this week/month/year
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'll probably won't be able to do trending this week/month/year with this current setup since we only store the score right now. I think other than that we probably want "TOP", but that's a different calculation altogether.
Not sure, any thoguhts/ideas?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure either, just trying to think ahead a bit for what other constrains might enter the mix. But also don't want to get too caught up to prevent this from moving forward :)