+ }
+ };
+ });
+ },
+
+ // Retrieve completed local games
+ getNext: function(upperDt, callback) {
+ dbOperation((err,db) => {
+ let objectStore = db
+ .transaction("games", "readonly")
+ .objectStore("games");
+ let index = objectStore.index("created");
+ const range = IDBKeyRange.upperBound(upperDt);
+ let games = [];
+ index.openCursor(range).onsuccess = function(event) {
+ let cursor = event.target.result;
+ if (!cursor) {
+ // Most recent games first:
+ games = games.sort((g1, g2) => g2.created - g1.created);
+ // TODO: 20 games showed per request is arbitrary
+ callback(games.slice(0, 20));
+ }
+ else {
+ // If there is still another cursor to go, keep running this code
+ let g = cursor.value;
+ if (g.score != "*") {
+ // Do not retrieve moves or clocks (unused in list mode)
+ g.movesCount = g.moves.length;
+ delete g.moves;
+ delete g.clocks;
+ delete g.initime;
+ games.push(g);
+ }
+ cursor.continue();
+ }