From 71eff925c0790c772c661608b04a2071b23d268f Mon Sep 17 00:00:00 2001 From: LexLuthr <88259624+LexLuthr@users.noreply.github.com> Date: Tue, 26 Sep 2023 19:14:30 +0400 Subject: [PATCH] fix: remove payloadRootCid lookup (#1721) * remove payloadRootCid lookup * refactor the if --- gql/resolver_piece.go | 33 --------------------------------- gql/schema.graphql | 3 --- react/src/LID.js | 27 +++++++-------------------- react/src/gql.js | 7 ------- 4 files changed, 7 insertions(+), 63 deletions(-) diff --git a/gql/resolver_piece.go b/gql/resolver_piece.go index b66837e8f..08b438758 100644 --- a/gql/resolver_piece.go +++ b/gql/resolver_piece.go @@ -223,39 +223,6 @@ func (r *resolver) PiecesWithPayloadCid(ctx context.Context, args struct{ Payloa return pieceCids, nil } -func (r *resolver) PiecesWithRootPayloadCid(ctx context.Context, args struct{ PayloadCid string }) ([]string, error) { - payloadCid, err := cid.Parse(args.PayloadCid) - if err != nil { - return nil, fmt.Errorf("%s is not a valid payload cid", args.PayloadCid) - } - - var pieceCidSet = make(map[string]struct{}) - - // Get boost deals by payload cid - boostDeals, err := r.dealsDB.ByRootPayloadCID(ctx, payloadCid) - if err != nil { - return nil, err - } - for _, dl := range boostDeals { - pieceCidSet[dl.ClientDealProposal.Proposal.PieceCID.String()] = struct{}{} - } - - // Get legacy markets deals by payload cid - legacyDeals, err := r.legacyDeals.ByPayloadCid(ctx, payloadCid) - if err != nil { - return nil, err - } - for _, dl := range legacyDeals { - pieceCidSet[dl.ClientDealProposal.Proposal.PieceCID.String()] = struct{}{} - } - - pieceCids := make([]string, 0, len(pieceCidSet)) - for pieceCid := range pieceCidSet { - pieceCids = append(pieceCids, pieceCid) - } - return pieceCids, nil -} - func (r *resolver) PieceIndexes(ctx context.Context, args struct{ PieceCid string }) ([]string, error) { var indexes []string pieceCid, err := cid.Parse(args.PieceCid) diff --git a/gql/schema.graphql b/gql/schema.graphql index 73a701617..3a15cdbc6 100644 --- a/gql/schema.graphql +++ b/gql/schema.graphql @@ -540,9 +540,6 @@ type RootQuery { """Get the pieces that contain a particular payload CID""" piecesWithPayloadCid(payloadCid: String!): [String!]! - """Get the pieces that have a particular root payload CID""" - piecesWithRootPayloadCid(payloadCid: String!): [String!]! - """Get the indexes for a particular piece CID""" pieceIndexes(pieceCid: String!): [String!]! diff --git a/react/src/LID.js b/react/src/LID.js index ffec134af..bab2ae802 100644 --- a/react/src/LID.js +++ b/react/src/LID.js @@ -3,7 +3,7 @@ import {useMutation, useQuery} from "@apollo/react-hooks"; import { LIDQuery, FlaggedPiecesQuery, PieceBuildIndexMutation, - PieceStatusQuery, PiecesWithPayloadCidQuery, PiecesWithRootPayloadCidQuery, FlaggedPiecesCountQuery + PieceStatusQuery, PiecesWithPayloadCidQuery, FlaggedPiecesCountQuery } from "./gql"; import moment from "moment"; import {DebounceInput} from 'react-debounce-input'; @@ -510,31 +510,18 @@ function SearchResults({searchQuery, setSearchQuery, showSearchPrompt}) { skip: !searchQuery }) - // Look up pieces by root payload cid - const rootPayloadRes = useQuery(PiecesWithRootPayloadCidQuery, { - variables: { - payloadCid: searchQuery - }, - // Don't do this query if the search query is empty - skip: !searchQuery - }) - - // If the requests for payload CID & root payload CID have completed + // If the requests for payload CID have completed var pieceCid = null var pieceCids = [] - if ((payloadRes || {}).data && (rootPayloadRes || {}).data) { - pieceCids = [...new Set([ - ...payloadRes.data.piecesWithPayloadCid, - ...rootPayloadRes.data.piecesWithRootPayloadCid - ])] - if (pieceCids.length === 0) { + if ((payloadRes || {}).data) { + if (payloadRes.data.piecesWithPayloadCid.length === 0) { // If there were no results for the lookup by payload CID, use the search // query for a lookup by piece CID pieceCid = searchQuery - } else if (pieceCids.length === 1) { + } else if (payloadRes.data.piecesWithPayloadCid.length === 1) { // If there was exactly one result for the lookup by payload CID, use // the piece CID for the lookup by piece CID - pieceCid = pieceCids[0] + pieceCid = payloadRes.data.piecesWithPayloadCid[0] } } @@ -548,7 +535,7 @@ function SearchResults({searchQuery, setSearchQuery, showSearchPrompt}) { skip: !pieceCid }) - if ((pieceRes || {}).loading || (payloadRes || {}).loading || (rootPayloadRes || {}).loading) { + if ((pieceRes || {}).loading || (payloadRes || {}).loading) { return
Loading ...
} diff --git a/react/src/gql.js b/react/src/gql.js index 2788983cb..55179aa60 100644 --- a/react/src/gql.js +++ b/react/src/gql.js @@ -451,12 +451,6 @@ const LegacyDealQuery = gql` } `; -const PiecesWithRootPayloadCidQuery = gql` - query AppPiecesWithRootPayloadCidQuery($payloadCid: String!) { - piecesWithRootPayloadCid(payloadCid: $payloadCid) - } -`; - const PiecesWithPayloadCidQuery = gql` query AppPiecesWithPayloadCidQuery($payloadCid: String!) { piecesWithPayloadCid(payloadCid: $payloadCid) @@ -814,7 +808,6 @@ export { IpniAdEntriesQuery, IpniAdEntriesCountQuery, IpniLatestAdQuery, - PiecesWithRootPayloadCidQuery, PiecesWithPayloadCidQuery, PieceBuildIndexMutation, PieceStatusQuery,