From 4168079e1aa9c1d395762a2f940760862f1eed24 Mon Sep 17 00:00:00 2001 From: Peter Rabbitson Date: Fri, 15 Apr 2022 19:13:28 +0000 Subject: [PATCH] Implement way to inactivate a piece_cid centrally --- misc/export_stats.bash | 7 ++++++- misc/pg_schema.sql | 11 ++++++++--- webapi/apiPendingProposals.go | 4 ++++ webapi/apiRequestPiece.go | 11 ++++++++++- 4 files changed, 28 insertions(+), 5 deletions(-) diff --git a/misc/export_stats.bash b/misc/export_stats.bash index e6e966f..eee1a2b 100755 --- a/misc/export_stats.bash +++ b/misc/export_stats.bash @@ -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 @@ -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 @@ -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 != '' diff --git a/misc/pg_schema.sql b/misc/pg_schema.sql index e34b0b0..76e7819 100644 --- a/misc/pg_schema.sql +++ b/misc/pg_schema.sql @@ -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 @@ -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' @@ -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; @@ -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 @@ -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 ) diff --git a/webapi/apiPendingProposals.go b/webapi/apiPendingProposals.go index 9259345..eb97c5a 100644 --- a/webapi/apiPendingProposals.go +++ b/webapi/apiPendingProposals.go @@ -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 @@ -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 diff --git a/webapi/apiRequestPiece.go b/webapi/apiRequestPiece.go index 2fc187d..dd06c5a 100644 --- a/webapi/apiRequestPiece.go +++ b/webapi/apiRequestPiece.go @@ -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, @@ -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