Skip to content
This repository has been archived by the owner on Apr 29, 2024. It is now read-only.

Commit

Permalink
Implement way to inactivate a piece_cid centrally
Browse files Browse the repository at this point in the history
  • Loading branch information
ribasushi committed Apr 15, 2022
1 parent 2bb2dcd commit 4168079
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 5 deletions.
7 changes: 6 additions & 1 deletion misc/export_stats.bash
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ ex_qap() {
FROM proposals pr
JOIN pieces p USING ( piece_cid )
WHERE
NOT COALESCE( (p.meta->'inactive')::BOOL, false )
AND
pr.proposal_success_cid IS NOT NULL
AND
pr.proposal_failstamp = 0
Expand All @@ -64,6 +66,8 @@ ex_qap() {
JOIN pieces p USING( piece_cid )
JOIN clients c USING ( client_id )
WHERE
NOT COALESCE( (p.meta->'inactive')::BOOL, false )
AND
pd.status = 'active'
AND
c.is_affiliated
Expand All @@ -83,7 +87,8 @@ ex_qap() {
FROM published_deals pd
JOIN clients c
ON c.client_id = pd.client_id AND c.is_affiliated AND pd.status = 'active'
JOIN pieces p USING( piece_cid )
JOIN pieces p
ON p.piece_cid = pd.piece_cid AND NOT COALESCE( (p.meta->'inactive')::BOOL, false )
RIGHT JOIN providers pr USING ( provider_id )
WHERE
pr.org_id != ''
Expand Down
11 changes: 8 additions & 3 deletions misc/pg_schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,8 @@ CREATE MATERIALIZED VIEW deallist_eligible AS (
FROM evergreen.pieces pi
LEFT JOIN datasets ds USING ( dataset_id )
WHERE
NOT COALESCE( (pi.meta->'inactive')::BOOL, false )
AND
-- there needs to be at least one active deal ( anywhere )
EXISTS (
SELECT 42
Expand All @@ -246,8 +248,6 @@ CREATE MATERIALIZED VIEW deallist_eligible AS (
WHERE
d1.piece_cid = pi.piece_cid
AND
c.is_affiliated
AND
d1.is_filplus
AND
d1.status = 'active'
Expand Down Expand Up @@ -561,6 +561,7 @@ CREATE MATERIALIZED VIEW replica_counts AS (
) agg
) AS pending
FROM pieces curpiece
WHERE NOT COALESCE( (meta->'inactive')::BOOL, false )
);
CREATE UNIQUE INDEX replica_counts_piece_cid ON evergreen.replica_counts ( piece_cid );
ANALYZE evergreen.replica_counts;
Expand Down Expand Up @@ -592,6 +593,8 @@ CREATE VIEW frontpage_stats_v0 AS (
JOIN published_deals pd USING ( piece_cid )
JOIN clients c USING ( client_id )
WHERE
NOT COALESCE( (p.meta->'inactive')::BOOL, false )
AND
pd.status = 'active'
AND
c.is_affiliated
Expand All @@ -602,7 +605,9 @@ CREATE VIEW frontpage_stats_v0 AS (
COUNT(*) AS unique_deals_count
FROM pieces p
WHERE
piece_cid IN (
NOT COALESCE( (p.meta->'inactive')::BOOL, false )
AND
p.piece_cid IN (
SELECT piece_cid
FROM published_deals pd
JOIN clients c USING ( client_id )
Expand Down
4 changes: 4 additions & 0 deletions webapi/apiPendingProposals.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ func apiListPendingProposals(c echo.Context) error {
FROM pieces p
JOIN proposals pr USING ( piece_cid )
WHERE
NOT COALESCE( (p.meta->'inactive')::BOOL, false )
AND
pr.proposal_failstamp = 0
AND
pr.activated_deal_id IS NULL
Expand Down Expand Up @@ -90,6 +92,8 @@ func apiListPendingProposals(c echo.Context) error {
JOIN pieces p USING ( piece_cid )
JOIN payloads pl USING ( piece_cid )
WHERE
NOT COALESCE( (p.meta->'inactive')::BOOL, false )
AND
pr.provider_id = $1
AND
( pr.start_by - NOW() ) > '1 hour'::INTERVAL
Expand Down
11 changes: 10 additions & 1 deletion webapi/apiRequestPiece.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,14 @@ func apiRequestPiece(c echo.Context) (defErr error) {
SELECT
EXISTS( SELECT 42 FROM pieces WHERE piece_cid = $1 ) AS valid_piece,
EXISTS(
SELECT 42
FROM pieces
WHERE
piece_cid = $1
AND
NOT COALESCE( (meta->'inactive')::BOOL, false )
) AS valid_piece,
( SELECT padded_size FROM pieces WHERE piece_cid = $1 ) AS padded_size,
( SELECT payload_cid FROM payloads WHERE piece_cid = $1 ) AS payload_cid,
Expand All @@ -113,6 +120,8 @@ func apiRequestPiece(c echo.Context) (defErr error) {
FROM pieces p
JOIN proposals pr USING ( piece_cid )
WHERE
NOT COALESCE( (p.meta->'inactive')::BOOL, false )
AND
pr.proposal_failstamp = 0
AND
pr.activated_deal_id IS NULL
Expand Down

0 comments on commit 4168079

Please sign in to comment.