-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: rename pinned to psaPinned (#1268)
Co-authored-by: Alan Shaw <alan.shaw@protocol.ai>
- Loading branch information
Showing
10 changed files
with
64 additions
and
24 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -334,5 +334,5 @@ export type NameItem = { | |
|
||
export type UsedStorage = { | ||
uploaded: number, | ||
pinned: number | ||
} | ||
psaPinned: number | ||
} |
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
39 changes: 39 additions & 0 deletions
39
packages/db/postgres/migrations/008-user-used-storage-update.sql
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,39 @@ | ||
DROP TYPE used_storage; | ||
CREATE TYPE stored_bytes AS (uploaded TEXT, psa_pinned TEXT); | ||
|
||
DROP FUNCTION user_used_storage(bigint); | ||
|
||
CREATE OR REPLACE FUNCTION user_used_storage(query_user_id BIGINT) | ||
RETURNS stored_bytes | ||
LANGUAGE plpgsql | ||
AS | ||
$$ | ||
DECLARE used_storage stored_bytes; | ||
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.psa_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
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