From c752487f9f64f1bd8bb7560554c7a5543d8b87e8 Mon Sep 17 00:00:00 2001 From: Alan Rynne Date: Fri, 12 Jan 2024 13:29:42 +0100 Subject: [PATCH] fix: CNX-7606 Fixes missing `Data` column error (#61) * fix: Result will now include parent commit object and no longer assume it will have children * fix: Keep metadata in joined table --- speckle/GetByUrl.pqm | 4 +-- speckle/api/Api.GetAllObjectChildren.pqm | 39 +++++++++++++++--------- speckle/helpers/CleanUpObjects.pqm | 2 +- 3 files changed, 28 insertions(+), 17 deletions(-) diff --git a/speckle/GetByUrl.pqm b/speckle/GetByUrl.pqm index 80d3819..9880f3d 100644 --- a/speckle/GetByUrl.pqm +++ b/speckle/GetByUrl.pqm @@ -1,5 +1,6 @@ let Fetch = Extension.LoadFunction("Api.Fetch.pqm"), + GetObject = Extension.LoadFunction("Api.GetObject.pqm"), GetAllObjectChildren = Extension.LoadFunction("Api.GetAllObjectChildren.pqm"), GetObjectFromCommit = Extension.LoadFunction("GetObjectFromCommit.pqm"), GetObjectFromBranch = Extension.LoadFunction("GetObjectFromBranch.pqm"), @@ -34,8 +35,7 @@ in GetObjectFromBranch(server, id, stream[branch]) else GetObjectFromBranch(server, id, "main"), - removeEmpty = Table.RemoveLastN(commitObjectsTable, 1), - addStreamUrl = Table.AddColumn(removeEmpty, "Stream URL", each server & "/streams/" & id), + addStreamUrl = Table.AddColumn(commitObjectsTable, "Stream URL", each server & "/streams/" & id), addParentObjectId = Table.AddColumn( addStreamUrl, "Commit Object ID", each Value.Metadata(commitObjectsTable)[objectId] ), diff --git a/speckle/api/Api.GetAllObjectChildren.pqm b/speckle/api/Api.GetAllObjectChildren.pqm index 3ad98fe..3ded47f 100644 --- a/speckle/api/Api.GetAllObjectChildren.pqm +++ b/speckle/api/Api.GetAllObjectChildren.pqm @@ -1,6 +1,7 @@ let Table.GenerateByPage = Extension.LoadFunction("Table.GenerateByPage.pqm"), Speckle.Api.GetObjectChildren = Extension.LoadFunction("Api.GetObjectChildren.pqm"), + Speckle.Api.GetObject = Extension.LoadFunction("Api.GetObject.pqm"), Extension.LoadFunction = (fileName as text) => let binary = Extension.Contents(fileName), asText = Text.FromBinary(binary) @@ -19,17 +20,27 @@ in // After every page, we check the "nextCursor" record on the metadata of the previous request. // Table.GenerateByPage will keep asking for more pages until we return null. (server as text, streamId as text, objectId as text, optional cursor as text) as table => - Table.GenerateByPage( - (previous) => - let - // if previous is null, then this is our first page of data - nextCursor = if (previous = null) then cursor else Value.Metadata(previous)[Cursor]?, - // if the cursor is null but the prevous page is not, we've reached the end - page = - if (previous <> null and nextCursor = null) then - null - else - Speckle.Api.GetObjectChildren(server, streamId, objectId, 1000, nextCursor) - in - page - ) meta [server = server, streamId = streamId, objectId = objectId] + let + parentObject = Speckle.Api.GetObject(server, streamId, objectId), + childrenTable = Table.GenerateByPage( + (previous) => + let + // if previous is null, then this is our first page of data + nextCursor = if (previous = null) then cursor else Value.Metadata(previous)[Cursor]?, + // if the cursor is null but the prevous page is not, we've reached the end + page = + if (previous <> null and nextCursor = null) then + null + else + Speckle.Api.GetObjectChildren(server, streamId, objectId, 1000, nextCursor) + in + page + ), + parentTable = Table.FromRecords({[data = parentObject]}), + resultTable = + if (Table.ColumnCount(childrenTable) = 0) then + parentTable + else + Table.Combine({parentTable, childrenTable}) + in + resultTable meta [server = server, streamId = streamId, objectId = objectId] diff --git a/speckle/helpers/CleanUpObjects.pqm b/speckle/helpers/CleanUpObjects.pqm index c1f7c12..bd5b588 100644 --- a/speckle/helpers/CleanUpObjects.pqm +++ b/speckle/helpers/CleanUpObjects.pqm @@ -14,4 +14,4 @@ ), removed = List.Select(removeTotals, each _[data][speckle_type] <> "Speckle.Core.Models.DataChunk") in - removed + try removed otherwise objects