use monotonic time for updates
This commit is contained in:
parent
931eb6a134
commit
e8a3c764e0
21
index.js
21
index.js
|
|
@ -6,6 +6,15 @@ var express = require('express');
|
||||||
|
|
||||||
const POLLING_TIMEOUT = 60000/*ms*/;
|
const POLLING_TIMEOUT = 60000/*ms*/;
|
||||||
|
|
||||||
|
let nextMonotonicTime = 1;
|
||||||
|
|
||||||
|
function monotonicTime() {
|
||||||
|
const now = +new Date();
|
||||||
|
const mono = (now >= nextMonotonicTime) ? now : nextMonotonicTime;
|
||||||
|
nextMonotonicTime = mono + 1;
|
||||||
|
return mono;
|
||||||
|
}
|
||||||
|
|
||||||
var appendJournal = (function() {
|
var appendJournal = (function() {
|
||||||
let lastJournalText = null;
|
let lastJournalText = null;
|
||||||
return function appendJournal(text) {
|
return function appendJournal(text) {
|
||||||
|
|
@ -53,6 +62,15 @@ const dbInit = (async function dbInit() {
|
||||||
CREATE INDEX IF NOT EXISTS games_modified ON games(modified)
|
CREATE INDEX IF NOT EXISTS games_modified ON games(modified)
|
||||||
`);
|
`);
|
||||||
|
|
||||||
|
const maxModified = await db.getAsync(`
|
||||||
|
SELECT MAX(modified) as result FROM games
|
||||||
|
`).catch(logDbError('maxModified'));
|
||||||
|
|
||||||
|
/* Just in case the system clock moved backward since the last record was written. */
|
||||||
|
if (maxModified && maxModified.result) {
|
||||||
|
nextMonotonicTime = maxModified.result + 1;
|
||||||
|
}
|
||||||
|
|
||||||
console.log('Connected to the SQLite database.');
|
console.log('Connected to the SQLite database.');
|
||||||
|
|
||||||
return db;
|
return db;
|
||||||
|
|
@ -286,7 +304,6 @@ function validateUpdate(body) {
|
||||||
async function postGameHandler(req, res, next) {
|
async function postGameHandler(req, res, next) {
|
||||||
res.set('Cache-Control', 'no-store');
|
res.set('Cache-Control', 'no-store');
|
||||||
|
|
||||||
const time = +new Date();
|
|
||||||
const gameId = req.params.gameId;
|
const gameId = req.params.gameId;
|
||||||
const body = validateUpdate(req.body);
|
const body = validateUpdate(req.body);
|
||||||
|
|
||||||
|
|
@ -300,6 +317,8 @@ async function postGameHandler(req, res, next) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const time = monotonicTime();
|
||||||
|
|
||||||
const params = {
|
const params = {
|
||||||
$gameId: gameId,
|
$gameId: gameId,
|
||||||
$lightName: '',
|
$lightName: '',
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue