This repository was archived by the owner on Oct 27, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcache.js
More file actions
42 lines (40 loc) · 1.32 KB
/
cache.js
File metadata and controls
42 lines (40 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
const {migrate, connection, Map, History} = require("./db/modelsB.js");
const localconfig = require('./localconfig');
const CronJob = require('cron').CronJob;
const sequelize = require('sequelize');
const got = require('got');
/**
* Visit periodically to save history paths on server cache.
*/
const job = new CronJob('0 12 */6 * * *', async function () {
console.log('start');
const histories = await History.findAll({
attributes: [
[sequelize.fn('MAX', sequelize.col('history.createdAt')), 'maxCreatedAt']
],
where: {
diff: true,
error: false
},
include: [{
model: Map,
attributes: ['id'],
where: {
published: true, // do not cache draft maps
history: true // do not cache maps with history off
}
}
],
group: [
['map.id']
]
});
for (const history of histories) {
const timestamp = new Date(history.dataValues.maxCreatedAt).getTime();
const dataUrl = localconfig.internalUrl + '/api/dataid/' + history.map.id;
await got(dataUrl);
const timedataUrl = localconfig.internalUrl + '/api/timedata?id=' + history.map.id + '×tamp=' + timestamp;
await got(timedataUrl);
}
});
job.start();