Bläddra i källkod

Улучшение fillCheckQueue

Book Pauk 2 år sedan
förälder
incheckning
45ea26810a
1 ändrade filer med 12 tillägg och 6 borttagningar
  1. 12 6
      server/core/BookUpdateChecker/BUCServer.js

+ 12 - 6
server/core/BookUpdateChecker/BUCServer.js

@@ -184,8 +184,8 @@ class BUCServer {
                     log(LM_WARN, `clean 'buc' table: deleted ${res.deleted}`);
                     log(LM_WARN, `clean 'buc' table: deleted ${res.deleted}`);
                 }
                 }
 
 
-                //rows = await db.select({table: 'buc', count: true});
-                //log(LM_WARN, `'buc' table length: ${rows[0].count}`);
+                rows = await db.select({table: 'buc', count: true});
+                log(LM_WARN, `'buc' table size: ${rows[0].count}`);
 
 
                 now = Date.now();
                 now = Date.now();
                 //выборка кандидатов
                 //выборка кандидатов
@@ -200,24 +200,30 @@ class BUCServer {
                     `
                     `
                 });
                 });
 
 
-//console.log(rows);
-
+                //формирование checkQueue
                 if (rows.length) {
                 if (rows.length) {
                     const ids = [];
                     const ids = [];
+                    const rowsToPush = [];
 
 
+                    //сначала выберем сколько надо
                     for (const row of rows) {
                     for (const row of rows) {
-                        if (this.checkQueue.length >= this.maxCheckQueueLength)
+                        if (this.checkQueue.length + rowsToPush.length >= this.maxCheckQueueLength)
                             break;
                             break;
 
 
+                        rowsToPush.push(row);
                         ids.push(row.id);
                         ids.push(row.id);
-                        this.checkQueue.push(row);
                     }
                     }
 
 
+                    //установим у них флаг "в обработке"
                     await db.update({
                     await db.update({
                         table: 'buc',
                         table: 'buc',
                         mod: `(r) => r.state = 1`,
                         mod: `(r) => r.state = 1`,
                         where: `@@id(${db.esc(ids)})`
                         where: `@@id(${db.esc(ids)})`
                     });
                     });
+
+                    //пушим в очередь, после этого их обработает periodicCheck
+                    for (const row of rowsToPush)
+                        this.checkQueue.push(row);
                     
                     
                     log(LM_WARN, `checkQueue: added ${ids.length} recs, total ${this.checkQueue.length}`);
                     log(LM_WARN, `checkQueue: added ${ids.length} recs, total ${this.checkQueue.length}`);
                 }
                 }