[server] only send active publink count

This commit is contained in:
Abhishek Shroff
2024-10-29 20:41:52 +05:30
parent 0a335b26d7
commit 32e3582c49
5 changed files with 9 additions and 9 deletions

View File

@@ -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
}

View File

@@ -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);

View File

@@ -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,

View File

@@ -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

View File

@@ -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;