From 020ef34fcb9022e4528d6dc051e618ce19e2c943 Mon Sep 17 00:00:00 2001 From: Jannik Schönartz Date: Sun, 4 Nov 2018 15:56:53 +0000 Subject: [iDoIT] Rework the import method to use batch requests The use of batch request reduce the import time from 1h 10+ min to about 5 min. --- server/api/backends.js | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) (limited to 'server/api/backends.js') diff --git a/server/api/backends.js b/server/api/backends.js index 77506ba..7729588 100644 --- a/server/api/backends.js +++ b/server/api/backends.js @@ -4,6 +4,7 @@ const ExternalBackends = require(path.join(__appdir, 'lib', 'external-backends') var db = require(path.join(__appdir, 'lib', 'sequelize')) var express = require('express') var router = express.Router() +var noAuthRouter = express.Router() // GET requests. @@ -119,7 +120,38 @@ router.get('/:id/synctypes', (req, res) => { }) }) -// POST requests +// vvvv TEST MEHTOD !!!! <---------------------------------------------------------- +noAuthRouter.get('/:id/test/getObjectTree', (req, res) => { + const id = req.params.id + db.backend.findOne({ where: { id: id } }).then(backend => { + if (backend) { + const ba = new ExternalBackends() + const instance = ba.getInstance(backend.type) + + // Get the backend with all the mapped groups. ! Only groups can have childs ! + db.backend.findOne({ where: { id: backend.id }, include: ['mappedGroups'] }).then(b => { + var objectData = [] + // Put all groups in the array to make a one session call which returns all needed informations. + b.mappedGroups.forEach(mGroup => { + const mG = mGroup.backend_x_group + const eid = mG.externalId + const gid = mGroup.id + objectData.push({ eid: eid, gid: gid }) + }) + // Get all the information needed from the backend instance. (For all object ids in the array) + var promise = new Promise(function (resolve) { + // resolve(instance.getDataTree(backend.credentials, objectData.slice(0, 200))) + resolve(instance.getDataTree(backend.credentials, objectData)) + }) + promise.then(data => { + res.send({ length: data.length, result: data }) + }) + }) + } else res.send({ error: 'error' }) + }) +}) +module.exports.noAuthRouter = noAuthRouter +// ^^^^ TEST MEHTOD !!!! <---------------------------------------------------------- /* * id: -- cgit v1.2.3-55-g7522