From 14f81bcc1b50116118bd421e2cdea7050fc1a890 Mon Sep 17 00:00:00 2001 From: Julien Dessaux Date: Wed, 13 Sep 2023 23:38:24 +0200 Subject: [javascript] reworked basic exploration with systems fetch after registering --- nodejs/automation/exploration.js | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) (limited to 'nodejs/automation') diff --git a/nodejs/automation/exploration.js b/nodejs/automation/exploration.js index b35efe0..e4f24f1 100644 --- a/nodejs/automation/exploration.js +++ b/nodejs/automation/exploration.js @@ -1,21 +1,11 @@ -import * as db from '../database/systems.js'; +import db from '../database/db.js'; +import * as dbSystems from '../database/systems.js'; import * as api from '../lib/api.js'; -// Retrieves all systems information, should be called only once after registering export async function init() { - if (db.isInit()) { - return; + const response = await api.send({endpoint: `/systems`, page: Math.max(1, Math.floor(dbSystems.getSystemsCount()/20)), priority: 100}); + if (response.error !== undefined) { + throw response; } - for (let page=1; true; ++page) { - const response = await api.send({endpoint: `/systems?limit=20&page=${page}`, priority:100}); - if (response.error !== undefined) { - throw response; - } - response.data.forEach(system => db.setSystem(system)); - if (response.meta.total <= response.meta.limit * page) { - break; - } - } - console.log('Finished retrieving all systems information'); - db.init(); + db.transaction(() => response.forEach(function(system) { try { dbSystems.addSystem(system); } catch {} }))(); } -- cgit v1.2.3