1
0
Fork 0
mirror of synced 2024-10-01 01:28:51 +13:00

Merge branch 'link-record-performance' of github.com:Budibase/budibase into endpoint-renaming

This commit is contained in:
mike12345567 2020-10-09 20:18:46 +01:00
commit abbf7fcc02
2 changed files with 15 additions and 12 deletions

View file

@ -82,29 +82,30 @@ exports.updateLinks = async function({
* then an array will be output, object input -> object output.
*/
exports.attachLinkInfo = async (instanceId, rows) => {
// handle a single row as well as multiple
// handle a single record as well as multiple
let wasArray = true
if (!(rows instanceof Array)) {
rows = [rows]
wasArray = false
}
let tableIds = [...new Set(rows.map(el => el.tableId))]
// start by getting all the link values for performance reasons
let responses = await Promise.all(
rows.map(row =>
let responses = [].concat.apply(
[],
await Promise.all(
tableIds.map(tableId =>
getLinkDocuments({
instanceId,
tableId: row.tableId,
rowId: row._id,
tableId: tableId,
includeDocs: IncludeDocs.EXCLUDE,
})
)
)
// can just use an index to access responses, order maintained
let index = 0
)
// now iterate through the rows and all field information
for (let row of rows) {
// get all links for row, ignore fieldName for now
const linkVals = responses[index++]
const linkVals = responses.filter(el => el.thisId === row._id)
for (let linkVal of linkVals) {
// work out which link pertains to this row
if (!(row[linkVal.fieldName] instanceof Array)) {

View file

@ -27,10 +27,12 @@ exports.createLinkView = async instanceId => {
let doc2 = doc.doc2
emit([doc1.tableId, doc1.rowId], {
id: doc2.rowId,
thisId: doc1.rowId,
fieldName: doc1.fieldName,
})
emit([doc2.tableId, doc2.rowId], {
id: doc1.rowId,
thisId: doc2.rowId,
fieldName: doc2.fieldName,
})
}