summaryrefslogtreecommitdiffstats
path: root/server/api/backends.js
diff options
context:
space:
mode:
authorJannik Schönartz2018-11-04 16:56:53 +0100
committerJannik Schönartz2018-11-04 16:56:53 +0100
commit020ef34fcb9022e4528d6dc051e618ce19e2c943 (patch)
treef2478f9d56e0a0e23db3c004c11211529ab86db6 /server/api/backends.js
parenteslint fix (diff)
downloadbas-020ef34fcb9022e4528d6dc051e618ce19e2c943.tar.gz
bas-020ef34fcb9022e4528d6dc051e618ce19e2c943.tar.xz
bas-020ef34fcb9022e4528d6dc051e618ce19e2c943.zip
[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.
Diffstat (limited to 'server/api/backends.js')
-rw-r--r--server/api/backends.js34
1 files changed, 33 insertions, 1 deletions
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: <BACKEND_ID>