diff --git a/packages/preview-service/render_page/src/app.js b/packages/preview-service/render_page/src/app.js index 2ba8d0f09..1d41dc440 100644 --- a/packages/preview-service/render_page/src/app.js +++ b/packages/preview-service/render_page/src/app.js @@ -1,4 +1,4 @@ -import { Viewer, Converter } from '@speckle/viewer' +import { Viewer } from '@speckle/viewer' let v = new Viewer({ container: document.getElementById('renderer'), showStats: false }) // v.on( 'load-progress', args => console.log( args ) ) @@ -6,7 +6,8 @@ let v = new Viewer({ container: document.getElementById('renderer'), showStats: window.v = v window.LoadData = async function LoadData(url) { - await v.loadObject(url, token) + // token is not used in this context, since the preview service talks directly to the DB + await v.loadObject(url, undefined) } window.onload = () => { diff --git a/packages/preview-service/routes/objects.js b/packages/preview-service/routes/objects.js index 9bd7c1ab8..fd7a271af 100644 --- a/packages/preview-service/routes/objects.js +++ b/packages/preview-service/routes/objects.js @@ -9,7 +9,7 @@ const { pipeline, PassThrough } = require('stream') let router = express.Router() // This method was copy-pasted from the server method, without authentication/authorization (this web service is an internal one) -router.get('/:streamId/:objectId', async function (req, res, next) { +router.get('/:streamId/:objectId', async function (req, res) { // Populate first object (the "commit") let obj = await getObject({ streamId: req.params.streamId, diff --git a/packages/preview-service/routes/preview.js b/packages/preview-service/routes/preview.js index df4204d9e..0f4af0432 100644 --- a/packages/preview-service/routes/preview.js +++ b/packages/preview-service/routes/preview.js @@ -1,4 +1,5 @@ 'use strict' +/* eslint-disable */ let express = require('express') let router = express.Router() @@ -151,7 +152,7 @@ async function getScreenshot(objectUrl) { // return imageBuffer } -router.get('/:streamId/:objectId', async function (req, res, next) { +router.get('/:streamId/:objectId', async function (req, res) { let objectUrl = `http://127.0.0.1:3001/streams/${req.params.streamId}/objects/${req.params.objectId}` /* let authToken = '' diff --git a/packages/server/app.js b/packages/server/app.js index 3c4f04b9d..ebbb6427a 100644 --- a/packages/server/app.js +++ b/packages/server/app.js @@ -79,7 +79,7 @@ exports.buildApolloServer = (optionOverrides) => { metricConnectedClients.dec() } }, - plugins: [require(`${appRoot}/logging/apolloPlugin`)], + plugins: [require('@/logging/apolloPlugin')], tracing: debug, introspection: true, playground: true, diff --git a/packages/server/logging/apolloPlugin.js b/packages/server/logging/apolloPlugin.js index 47b9ad15f..ae14ea952 100644 --- a/packages/server/logging/apolloPlugin.js +++ b/packages/server/logging/apolloPlugin.js @@ -11,6 +11,7 @@ const metricCallCount = new prometheusClient.Counter({ }) module.exports = { + // eslint-disable-next-line no-unused-vars requestDidStart(ctx) { return { didResolveOperation(ctx) { diff --git a/packages/server/modules/core/services/objects.js b/packages/server/modules/core/services/objects.js index 32f87ef9a..8a0285876 100644 --- a/packages/server/modules/core/services/objects.js +++ b/packages/server/modules/core/services/objects.js @@ -134,70 +134,68 @@ module.exports = { let ids = [] - let promises = batches.map( - async (batch, index) => - new Promise(async (resolve, reject) => { - let closures = [] - let objsToInsert = [] + const insertBatch = async (batch, index) => { + let closures = [] + let objsToInsert = [] - let t0 = performance.now() + let t0 = performance.now() - batch.forEach((obj) => { - if (!obj) return + batch.forEach((obj) => { + if (!obj) return - let insertionObject = prepInsertionObject(streamId, obj) - let totalChildrenCountByDepth = {} - let totalChildrenCountGlobal = 0 - if (obj.__closure !== null) { - for (const prop in obj.__closure) { - closures.push({ - streamId: streamId, - parent: insertionObject.id, - child: prop, - minDepth: obj.__closure[prop] - }) + let insertionObject = prepInsertionObject(streamId, obj) + let totalChildrenCountByDepth = {} + let totalChildrenCountGlobal = 0 + if (obj.__closure !== null) { + for (const prop in obj.__closure) { + closures.push({ + streamId: streamId, + parent: insertionObject.id, + child: prop, + minDepth: obj.__closure[prop] + }) - totalChildrenCountGlobal++ + totalChildrenCountGlobal++ - if (totalChildrenCountByDepth[obj.__closure[prop].toString()]) - totalChildrenCountByDepth[obj.__closure[prop].toString()]++ - else totalChildrenCountByDepth[obj.__closure[prop].toString()] = 1 - } - } - - insertionObject.totalChildrenCount = totalChildrenCountGlobal - insertionObject.totalChildrenCountByDepth = JSON.stringify( - totalChildrenCountByDepth - ) - - delete insertionObject.__tree - delete insertionObject.__closure - - objsToInsert.push(insertionObject) - ids.push(insertionObject.id) - }) - - if (objsToInsert.length > 0) { - let queryObjs = - Objects().insert(objsToInsert).toString() + ' on conflict do nothing' - await knex.raw(queryObjs) + if (totalChildrenCountByDepth[obj.__closure[prop].toString()]) + totalChildrenCountByDepth[obj.__closure[prop].toString()]++ + else totalChildrenCountByDepth[obj.__closure[prop].toString()] = 1 } + } - if (closures.length > 0) { - let q2 = `${Closures().insert(closures).toString()} on conflict do nothing` - await knex.raw(q2) - } + insertionObject.totalChildrenCount = totalChildrenCountGlobal + insertionObject.totalChildrenCountByDepth = JSON.stringify( + totalChildrenCountByDepth + ) - let t1 = performance.now() - debug( - `Batch ${index + 1}/${batches.length}: Stored ${ - closures.length + objsToInsert.length - } objects in ${t1 - t0}ms.` - ) - // console.log( `Batch ${index + 1}/${batches.length}: Stored ${closures.length + objsToInsert.length} objects in ${t1-t0}ms.` ) - resolve() - }) - ) + delete insertionObject.__tree + delete insertionObject.__closure + + objsToInsert.push(insertionObject) + ids.push(insertionObject.id) + }) + + if (objsToInsert.length > 0) { + let queryObjs = + Objects().insert(objsToInsert).toString() + ' on conflict do nothing' + await knex.raw(queryObjs) + } + + if (closures.length > 0) { + let q2 = `${Closures().insert(closures).toString()} on conflict do nothing` + await knex.raw(q2) + } + + let t1 = performance.now() + debug( + `Batch ${index + 1}/${batches.length}: Stored ${ + closures.length + objsToInsert.length + } objects in ${t1 - t0}ms.` + ) + // console.log( `Batch ${index + 1}/${batches.length}: Stored ${closures.length + objsToInsert.length} objects in ${t1-t0}ms.` ) + } + + let promises = batches.map((batch, index) => insertBatch(batch, index)) await Promise.all(promises)