Vulcan/packages/nova-voting/lib/cron.js

42 lines
1.6 KiB
JavaScript
Raw Normal View History

2017-03-23 16:27:59 +09:00
import Posts from "meteor/vulcan:posts";
import Comments from "meteor/vulcan:comments";
import { getSetting } from 'meteor/vulcan:core';
import { updateScore } from './scoring.js';
2016-06-23 11:40:35 +09:00
// TODO use a node cron or at least synced-cron
2016-12-09 09:11:20 +01:00
Meteor.startup(function () {
2016-12-12 15:00:56 +09:00
const scoreInterval = parseInt(getSetting("scoreUpdateInterval")) || 30;
2016-12-09 09:11:20 +01:00
if (scoreInterval > 0) {
2016-12-09 09:11:20 +01:00
// active items get updated every N seconds
Meteor.setInterval(function () {
let updatedPosts = 0;
let updatedComments = 0;
2016-12-09 09:11:20 +01:00
// console.log('tick ('+scoreInterval+')');
Posts.find({'status': 2,'inactive': {$ne : true}}).forEach(function (post) { // only run scoring on approved posts
updatedPosts += updateScore({collection: Posts, item: post});
2016-12-09 09:11:20 +01:00
});
Comments.find({'inactive': {$ne : true}}).forEach(function (comment) {
updatedComments += updateScore({collection: Comments, item: comment});
2016-12-09 09:11:20 +01:00
});
// console.log("Updated "+updatedPosts+"/"+Posts.find().count()+" Posts")
// console.log("Updated "+updatedComments+"/"+Comments.find().count()+" Comments")
}, scoreInterval * 1000);
2016-12-09 09:11:20 +01:00
// inactive items get updated every hour
Meteor.setInterval(function () {
let updatedPosts = 0;
let updatedComments = 0;
2016-12-09 09:11:20 +01:00
Posts.find({'inactive': true}).forEach(function (post) {
updatedPosts += updateScore({collection: Posts, item: post});
2016-12-09 09:11:20 +01:00
});
Comments.find({'inactive': true}).forEach(function (comment) {
updatedComments += updateScore({collection: Comments, item: comment});
2016-12-09 09:11:20 +01:00
});
}, 3600 * 1000);
}
});