Skip to content

Commit

Permalink
fix: CNX-7606 Fixes missing Data column error (#61)
Browse files Browse the repository at this point in the history
* fix: Result will now include parent commit object and no longer assume it will have children

* fix: Keep metadata in joined table
  • Loading branch information
AlanRynne authored Jan 12, 2024
1 parent 95f51b0 commit c752487
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 17 deletions.
4 changes: 2 additions & 2 deletions speckle/GetByUrl.pqm
Original file line number Diff line number Diff line change
@@ -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"),
Expand Down Expand Up @@ -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]
),
Expand Down
39 changes: 25 additions & 14 deletions speckle/api/Api.GetAllObjectChildren.pqm
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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]
2 changes: 1 addition & 1 deletion speckle/helpers/CleanUpObjects.pqm
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
),
removed = List.Select(removeTotals, each _[data][speckle_type] <> "Speckle.Core.Models.DataChunk")
in
removed
try removed otherwise objects

0 comments on commit c752487

Please sign in to comment.