Merge branch 'link-record-performance' of github.com:Budibase/budibase into endpoint-renaming
This commit is contained in:
commit
abbf7fcc02
|
@ -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 =>
|
||||
getLinkDocuments({
|
||||
instanceId,
|
||||
tableId: row.tableId,
|
||||
rowId: row._id,
|
||||
includeDocs: IncludeDocs.EXCLUDE,
|
||||
})
|
||||
let responses = [].concat.apply(
|
||||
[],
|
||||
await Promise.all(
|
||||
tableIds.map(tableId =>
|
||||
getLinkDocuments({
|
||||
instanceId,
|
||||
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)) {
|
||||
|
|
|
@ -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,
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue