-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add pinned storage to user account API (#1044)
- Loading branch information
1 parent
aa4785f
commit 3200a6e
Showing
14 changed files
with
228 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
CREATE TYPE used_storage AS (uploaded TEXT, pinned TEXT); | ||
|
||
DROP FUNCTION user_used_storage(bigint); | ||
|
||
CREATE OR REPLACE FUNCTION user_used_storage(query_user_id BIGINT) | ||
RETURNS used_storage | ||
LANGUAGE plpgsql | ||
AS | ||
$$ | ||
DECLARE used_storage used_storage; | ||
BEGIN | ||
SELECT COALESCE(SUM(c.dag_size), 0) | ||
INTO used_storage.uploaded::TEXT | ||
FROM upload u | ||
JOIN content c ON c.cid = u.content_cid | ||
WHERE u.user_id = query_user_id::BIGINT | ||
AND u.deleted_at is null; | ||
|
||
SELECT COALESCE(( | ||
SELECT SUM(dag_size) | ||
FROM ( | ||
SELECT psa_pr.content_cid, | ||
c.dag_size | ||
FROM psa_pin_request psa_pr | ||
JOIN content c ON c.cid = psa_pr.content_cid | ||
JOIN pin p ON p.content_cid = psa_pr.content_cid | ||
JOIN auth_key a ON a.id = psa_pr.auth_key_id | ||
WHERE a.user_id = query_user_id::BIGINT | ||
AND psa_pr.deleted_at is null | ||
AND p.status = 'Pinned' | ||
GROUP BY psa_pr.content_cid, | ||
c.dag_size | ||
) AS pinned_content), 0) | ||
INTO used_storage.pinned::TEXT; | ||
|
||
return used_storage; | ||
END | ||
$$; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.