Vulcan/packages/_nova-voting/lib/server/cron.js

34 lines
1.4 KiB
JavaScript
Raw Normal View History

Meteor.startup(function () {
var scoreInterval = Settings.get("scoreUpdateInterval") || 30;
if (scoreInterval > 0) {
// active items get updated every N seconds
Meteor.setInterval(function () {
var updatedPosts = 0;
var updatedComments = 0;
// console.log('tick ('+scoreInterval+')');
Posts.find({'status': 2,'inactive': {$ne : true}}).forEach(function (post) { // only run scoring on approved posts
2015-04-23 11:11:07 +09:00
updatedPosts += Telescope.updateScore({collection: Posts, item: post});
});
Comments.find({'inactive': {$ne : true}}).forEach(function (comment) {
2015-04-23 11:11:07 +09:00
updatedComments += Telescope.updateScore({collection: Comments, item: comment});
});
// console.log("Updated "+updatedPosts+"/"+Posts.find().count()+" Posts")
// console.log("Updated "+updatedComments+"/"+Comments.find().count()+" Comments")
}, scoreInterval * 1000);
// inactive items get updated every hour
Meteor.setInterval(function () {
var updatedPosts = 0;
var updatedComments = 0;
Posts.find({'inactive': true}).forEach(function (post) {
2015-04-23 11:11:07 +09:00
updatedPosts += Telescope.updateScore({collection: Posts, item: post});
});
Comments.find({'inactive': true}).forEach(function (comment) {
2015-04-23 11:11:07 +09:00
updatedComments += Telescope.updateScore({collection: Comments, item: comment});
});
}, 3600 * 1000);
}
});