diff --git a/server/internal/core/db/fs.sql.go b/server/internal/core/db/fs.sql.go index 49104f5c..7898557a 100644 --- a/server/internal/core/db/fs.sql.go +++ b/server/internal/core/db/fs.sql.go @@ -167,9 +167,9 @@ WITH RECURSIVE nodes(id, parent, name, dir, created, modified, content_size, con AND r.id != $2::uuid AND CASE WHEN $3::boolean THEN true ELSE depth < 1 END ), links(id, count) AS ( - SELECT root, count(p.id) FROM publinks p GROUP BY p.root + SELECT root, count(p.id) FROM publinks p WHERE p.deleted IS NULL GROUP BY p.root ) -SELECT nodes.id, nodes.parent, nodes.name, nodes.dir, nodes.created, nodes.modified, nodes.content_size, nodes.content_type, nodes.content_sha256, nodes.depth, nodes.path, nodes.permissions, COALESCE(links.count, 0) from nodes +SELECT nodes.id, nodes.parent, nodes.name, nodes.dir, nodes.created, nodes.modified, nodes.content_size, nodes.content_type, nodes.content_sha256, nodes.depth, nodes.path, nodes.permissions, COALESCE(links.count, 0) AS publinks from nodes LEFT JOIN links ON nodes.id = links.id WHERE CASE WHEN $1::boolean THEN true ELSE depth > 0 END ` @@ -193,7 +193,7 @@ type ReadDirRow struct { Depth int32 Path string Permissions []byte - Count int64 + Publinks int64 } func (q *Queries) ReadDir(ctx context.Context, arg ReadDirParams) ([]ReadDirRow, error) { @@ -218,7 +218,7 @@ func (q *Queries) ReadDir(ctx context.Context, arg ReadDirParams) ([]ReadDirRow, &i.Depth, &i.Path, &i.Permissions, - &i.Count, + &i.Publinks, ); err != nil { return nil, err } diff --git a/server/internal/core/db/migrations/data/005_publink.sql b/server/internal/core/db/migrations/data/005_publink.sql index 2c915a8d..b58c8fd7 100644 --- a/server/internal/core/db/migrations/data/005_publink.sql +++ b/server/internal/core/db/migrations/data/005_publink.sql @@ -13,7 +13,7 @@ CREATE TABLE publinks( CREATE UNIQUE INDEX unique_publink ON publinks(name) WHERE deleted IS NULL; -CREATE INDEX publinks_by_root ON publinks(root); +CREATE INDEX publinks_by_root ON publinks(root, deleted); CREATE INDEX publinks_by_creator ON publinks(created_by); diff --git a/server/internal/core/db/migrations/data/006_resource_by_id.sql b/server/internal/core/db/migrations/data/006_resource_by_id.sql index d3312395..408facc5 100644 --- a/server/internal/core/db/migrations/data/006_resource_by_id.sql +++ b/server/internal/core/db/migrations/data/006_resource_by_id.sql @@ -52,7 +52,7 @@ CREATE FUNCTION resource_by_id(resource_id uuid, root uuid, username text) RETUR JOIN nodes n ON r.id = n.parent ), links(id, count) AS ( - SELECT root, count(p.id) FROM publinks p GROUP BY p.root + SELECT root, count(p.id) FROM publinks p WHERE p.deleted IS NULL GROUP BY p.root ) SELECT resid AS id, diff --git a/server/internal/core/fs/open.go b/server/internal/core/fs/open.go index 5a32874e..d3bbcc38 100644 --- a/server/internal/core/fs/open.go +++ b/server/internal/core/fs/open.go @@ -65,7 +65,7 @@ func (r Resource) ReadDir(recursive bool) ([]serve.Resource, error) { ContentType: c.ContentType, ContentSHA256: c.ContentSha256, Permissions: string(c.Permissions), - Publinks: int(r.Publinks), + Publinks: int(c.Publinks), Path: path, UserPermissions: r.UserPermissions, // Not Needed diff --git a/server/sql/queries/fs.sql b/server/sql/queries/fs.sql index fb191d01..1d2d9d4f 100644 --- a/server/sql/queries/fs.sql +++ b/server/sql/queries/fs.sql @@ -91,9 +91,9 @@ WITH RECURSIVE nodes(id, parent, name, dir, created, modified, content_size, con AND r.id != @id::uuid AND CASE WHEN @recursive::boolean THEN true ELSE depth < 1 END ), links(id, count) AS ( - SELECT root, count(p.id) FROM publinks p GROUP BY p.root + SELECT root, count(p.id) FROM publinks p WHERE p.deleted IS NULL GROUP BY p.root ) -SELECT nodes.*, COALESCE(links.count, 0) from nodes +SELECT nodes.*, COALESCE(links.count, 0) AS publinks from nodes LEFT JOIN links ON nodes.id = links.id WHERE CASE WHEN @include_root::boolean THEN true ELSE depth > 0 END;