Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:bug: Preserve published backlink ordering https://github.com/siyuan-note/siyuan/issues/18733

Danielc11c9f28aef7
diff --git a/kernel/model/publish_access.go b/kernel/model/publish_access.go
index 503b6ba765..2ef54be51d 100644
--- a/kernel/model/publish_access.go
+++ b/kernel/model/publish_access.go
@@ -1297,18 +1297,15 @@ func FilterPathsByPublishAccess(c *gin.Context, publishAccess PublishAccess, pat
publishInvisible := GetInvisiblePublishAccess(publishAccess)
publishDisable := GetDisablePublishAccess(publishAccess)
- IDtoPathIndexMap := make(map[string]int)
- for i, path := range paths {
+ for _, path := range paths {
IDs = append(IDs, path.ID)
- IDtoPathIndexMap[path.ID] = i
}
bts := treenode.GetBlockTrees(IDs)
- for _, bt := range bts {
+ for _, path := range paths {
+ bt := bts[path.ID]
if bt == nil {
continue
}
- pathIndex := IDtoPathIndexMap[bt.ID]
- path := paths[pathIndex]
passwordID, password := GetPathPasswordByPublishAccess(bt.BoxID, bt.Path, publishAccess)
if CheckPathAccessableByPublishIgnore(bt.BoxID, bt.Path, publishInvisible) &&
CheckPathAccessableByPublishIgnore(bt.BoxID, bt.Path, publishDisable) &&
diff --git a/kernel/model/publish_access_test.go b/kernel/model/publish_access_test.go
index 059f77216b..484f3c6075 100644
--- a/kernel/model/publish_access_test.go
+++ b/kernel/model/publish_access_test.go
@@ -1167,8 +1167,8 @@ func TestFilterPathsByPublishAccess(t *testing.T) {
newPaths := func() []*Path {
return []*Path{
- {ID: publicID, Name: "/" + publicID + ".sy", HPath: "/public", Type: "path", NodeType: "NodeDocument"},
{ID: protectedID, Name: "/" + protectedID + ".sy", HPath: "/protected", Type: "path", NodeType: "NodeDocument"},
+ {ID: publicID, Name: "/" + publicID + ".sy", HPath: "/public", Type: "path", NodeType: "NodeDocument"},
{ID: hiddenID, Name: "/" + hiddenID + ".sy", HPath: "/hidden", Type: "path", NodeType: "NodeDocument"},
{ID: disabledID, Name: "/" + disabledID + ".sy", HPath: "/disabled", Type: "path", NodeType: "NodeDocument"},
}
@@ -1191,7 +1191,7 @@ func TestFilterPathsByPublishAccess(t *testing.T) {
Value: util.SHA256Hash([]byte(protectedID + protectedPassword)),
})
filtered = FilterPathsByPublishAccess(c, publishAccess, newPaths())
- if len(filtered) != 2 || filtered[0].ID != publicID || filtered[1].ID != protectedID {
+ if len(filtered) != 2 || filtered[0].ID != protectedID || filtered[1].ID != publicID {
t.Fatalf("unexpected authenticated backlink paths: %+v", filtered)
}
}