Skip to content

Commit

Permalink
retrieve last wiki edit time less frequently
Browse files Browse the repository at this point in the history
  • Loading branch information
umaar committed Sep 26, 2018
1 parent 8ddbcd7 commit eefd33d
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ const wikimediaStreamURL = 'https://stream.wikimedia.org/v2/stream/recentchange'

const locationCache = LRU(1000);

let latestWikiEditTime;

async function updateLatestWikiEditTime() {
const last = await knex.from('edits').orderBy('id', 'desc').first();
latestWikiEditTime = last.edit_time;
}

setInterval(updateLatestWikiEditTime, 10000);

const timeKeys = {
'past-1-hour'(date) {
date.setHours(date.getHours() - 1);
Expand Down Expand Up @@ -145,7 +154,8 @@ function registerWebhook(app) {
}
}

function init() {
async function init() {
await updateLatestWikiEditTime();
function daMiddleWarez(req, res, next) {
const {path, query} = req;

Expand All @@ -170,9 +180,6 @@ function init() {
console.log('Connection established');

socket.on('message', async function({selectedTime, offset = 0}) {
const last = await knex.from('edits').orderBy('id', 'desc').first();
const latestWikiEditTime = last.edit_time;

const allowedTimeRangeKeys = Object.keys(timeKeys);

if (!allowedTimeRangeKeys.includes(selectedTime)) {
Expand Down

0 comments on commit eefd33d

Please sign in to comment.