Acceptable state, but still issues when a lot of moves arrive quickly on several...
[vchess.git] / client / src / utils / gameStorage.js
index ce609af..2e78994 100644 (file)
@@ -83,7 +83,7 @@ export const GameStorage = {
         objectStore.get(gameId).onsuccess = function(event) {
           // Ignoring error silently: shouldn't happen now. TODO?
           if (event.target.result) {
-            const game = event.target.result;
+            let game = event.target.result;
             Object.keys(obj).forEach(k => {
               if (k == "move") game.moves.push(obj[k]);
               else game[k] = obj[k];
@@ -96,7 +96,8 @@ export const GameStorage = {
   },
 
   // Retrieve all local games (running, completed, imported...)
-  getAll: function(callback) {
+  // light: do not retrieve moves or clocks (TODO: this is the only usage)
+  getAll: function(light, callback) {
     dbOperation((err,db) => {
       let objectStore = db.transaction("games").objectStore("games");
       let games = [];
@@ -104,7 +105,14 @@ export const GameStorage = {
         let cursor = event.target.result;
         // if there is still another cursor to go, keep running this code
         if (cursor) {
-          games.push(cursor.value);
+          let g = cursor.value;
+          if (light) {
+            g.movesCount = g.moves.length;
+            delete g.moves;
+            delete g.clocks;
+            delete g.initime;
+          }
+          games.push(g);
           cursor.continue();
         } else callback(games);
       };