mirror of
https://github.com/vale981/Vulcan
synced 2025-03-06 01:51:40 -05:00
Order of operation fix in scoring.js
This commit is contained in:
parent
7ff103f806
commit
b496d01d83
1 changed files with 8 additions and 7 deletions
|
@ -10,17 +10,18 @@ Returns how many documents have been updated (1 or 0).
|
|||
export const updateScore = ({collection, item, forceUpdate}) => {
|
||||
|
||||
// Age Check
|
||||
|
||||
// If for some reason item doesn't have a "postedAt" property, abort
|
||||
// Or, if post has been scheduled in the future, don't update its score
|
||||
if (!item.postedAt || postedAt > now)
|
||||
return 0;
|
||||
|
||||
const postedAt = item.postedAt.valueOf();
|
||||
const postedAt = item && item.postedAt && item.postedAt.valueOf();
|
||||
const now = new Date().getTime();
|
||||
const age = now - postedAt;
|
||||
const ageInHours = age / (60 * 60 * 1000);
|
||||
|
||||
// If for some reason item doesn't have a "postedAt" property, abort
|
||||
// Or, if post has been scheduled in the future, don't update its score
|
||||
if (postedAt || postedAt > now)
|
||||
return 0;
|
||||
|
||||
|
||||
|
||||
// For performance reasons, the database is only updated if the difference between the old score and the new score
|
||||
// is meaningful enough. To find out, we calculate the "power" of a single vote after n days.
|
||||
// We assume that after n days, a single vote will not be powerful enough to affect posts' ranking order.
|
||||
|
|
Loading…
Add table
Reference in a new issue