2016-12-09 09:11:20 +01:00
|
|
|
import Telescope from 'meteor/nova:lib';
|
|
|
|
import Posts from "meteor/nova:posts";
|
|
|
|
import Comments from "meteor/nova:comments";
|
2016-06-23 11:40:35 +09:00
|
|
|
|
2016-12-09 09:11:20 +01:00
|
|
|
Meteor.startup(function () {
|
|
|
|
const scoreInterval = parseInt(Telescope.settings.get("scoreUpdateInterval")) || 30;
|
|
|
|
if (scoreInterval > 0) {
|
2015-04-22 08:31:11 +09:00
|
|
|
|
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-11-26 02:46:55 +08:00
|
|
|
|
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 += Telescope.updateScore({collection: Posts, item: post});
|
|
|
|
});
|
|
|
|
Comments.find({'inactive': {$ne : true}}).forEach(function (comment) {
|
|
|
|
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);
|
2015-04-22 08:31:11 +09:00
|
|
|
|
2016-12-09 09:11:20 +01:00
|
|
|
// inactive items get updated every hour
|
|
|
|
Meteor.setInterval(function () {
|
|
|
|
let updatedPosts = 0;
|
|
|
|
let updatedComments = 0;
|
2015-04-22 08:31:11 +09:00
|
|
|
|
2016-12-09 09:11:20 +01:00
|
|
|
Posts.find({'inactive': true}).forEach(function (post) {
|
|
|
|
updatedPosts += Telescope.updateScore({collection: Posts, item: post});
|
|
|
|
});
|
|
|
|
Comments.find({'inactive': true}).forEach(function (comment) {
|
|
|
|
updatedComments += Telescope.updateScore({collection: Comments, item: comment});
|
|
|
|
});
|
|
|
|
}, 3600 * 1000);
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|