Skip to content

Commit 71eff92

Browse files
authored
fix: remove payloadRootCid lookup (#1721)
* remove payloadRootCid lookup * refactor the if
1 parent 946fc34 commit 71eff92

File tree

4 files changed

+7
-63
lines changed

4 files changed

+7
-63
lines changed

gql/resolver_piece.go

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -223,39 +223,6 @@ func (r *resolver) PiecesWithPayloadCid(ctx context.Context, args struct{ Payloa
223223
return pieceCids, nil
224224
}
225225

226-
func (r *resolver) PiecesWithRootPayloadCid(ctx context.Context, args struct{ PayloadCid string }) ([]string, error) {
227-
payloadCid, err := cid.Parse(args.PayloadCid)
228-
if err != nil {
229-
return nil, fmt.Errorf("%s is not a valid payload cid", args.PayloadCid)
230-
}
231-
232-
var pieceCidSet = make(map[string]struct{})
233-
234-
// Get boost deals by payload cid
235-
boostDeals, err := r.dealsDB.ByRootPayloadCID(ctx, payloadCid)
236-
if err != nil {
237-
return nil, err
238-
}
239-
for _, dl := range boostDeals {
240-
pieceCidSet[dl.ClientDealProposal.Proposal.PieceCID.String()] = struct{}{}
241-
}
242-
243-
// Get legacy markets deals by payload cid
244-
legacyDeals, err := r.legacyDeals.ByPayloadCid(ctx, payloadCid)
245-
if err != nil {
246-
return nil, err
247-
}
248-
for _, dl := range legacyDeals {
249-
pieceCidSet[dl.ClientDealProposal.Proposal.PieceCID.String()] = struct{}{}
250-
}
251-
252-
pieceCids := make([]string, 0, len(pieceCidSet))
253-
for pieceCid := range pieceCidSet {
254-
pieceCids = append(pieceCids, pieceCid)
255-
}
256-
return pieceCids, nil
257-
}
258-
259226
func (r *resolver) PieceIndexes(ctx context.Context, args struct{ PieceCid string }) ([]string, error) {
260227
var indexes []string
261228
pieceCid, err := cid.Parse(args.PieceCid)

gql/schema.graphql

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -540,9 +540,6 @@ type RootQuery {
540540
"""Get the pieces that contain a particular payload CID"""
541541
piecesWithPayloadCid(payloadCid: String!): [String!]!
542542

543-
"""Get the pieces that have a particular root payload CID"""
544-
piecesWithRootPayloadCid(payloadCid: String!): [String!]!
545-
546543
"""Get the indexes for a particular piece CID"""
547544
pieceIndexes(pieceCid: String!): [String!]!
548545

react/src/LID.js

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {useMutation, useQuery} from "@apollo/react-hooks";
33
import {
44
LIDQuery,
55
FlaggedPiecesQuery, PieceBuildIndexMutation,
6-
PieceStatusQuery, PiecesWithPayloadCidQuery, PiecesWithRootPayloadCidQuery, FlaggedPiecesCountQuery
6+
PieceStatusQuery, PiecesWithPayloadCidQuery, FlaggedPiecesCountQuery
77
} from "./gql";
88
import moment from "moment";
99
import {DebounceInput} from 'react-debounce-input';
@@ -510,31 +510,18 @@ function SearchResults({searchQuery, setSearchQuery, showSearchPrompt}) {
510510
skip: !searchQuery
511511
})
512512

513-
// Look up pieces by root payload cid
514-
const rootPayloadRes = useQuery(PiecesWithRootPayloadCidQuery, {
515-
variables: {
516-
payloadCid: searchQuery
517-
},
518-
// Don't do this query if the search query is empty
519-
skip: !searchQuery
520-
})
521-
522-
// If the requests for payload CID & root payload CID have completed
513+
// If the requests for payload CID have completed
523514
var pieceCid = null
524515
var pieceCids = []
525-
if ((payloadRes || {}).data && (rootPayloadRes || {}).data) {
526-
pieceCids = [...new Set([
527-
...payloadRes.data.piecesWithPayloadCid,
528-
...rootPayloadRes.data.piecesWithRootPayloadCid
529-
])]
530-
if (pieceCids.length === 0) {
516+
if ((payloadRes || {}).data) {
517+
if (payloadRes.data.piecesWithPayloadCid.length === 0) {
531518
// If there were no results for the lookup by payload CID, use the search
532519
// query for a lookup by piece CID
533520
pieceCid = searchQuery
534-
} else if (pieceCids.length === 1) {
521+
} else if (payloadRes.data.piecesWithPayloadCid.length === 1) {
535522
// If there was exactly one result for the lookup by payload CID, use
536523
// the piece CID for the lookup by piece CID
537-
pieceCid = pieceCids[0]
524+
pieceCid = payloadRes.data.piecesWithPayloadCid[0]
538525
}
539526
}
540527

@@ -548,7 +535,7 @@ function SearchResults({searchQuery, setSearchQuery, showSearchPrompt}) {
548535
skip: !pieceCid
549536
})
550537

551-
if ((pieceRes || {}).loading || (payloadRes || {}).loading || (rootPayloadRes || {}).loading) {
538+
if ((pieceRes || {}).loading || (payloadRes || {}).loading) {
552539
return <div>Loading ...</div>
553540
}
554541

react/src/gql.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -451,12 +451,6 @@ const LegacyDealQuery = gql`
451451
}
452452
`;
453453

454-
const PiecesWithRootPayloadCidQuery = gql`
455-
query AppPiecesWithRootPayloadCidQuery($payloadCid: String!) {
456-
piecesWithRootPayloadCid(payloadCid: $payloadCid)
457-
}
458-
`;
459-
460454
const PiecesWithPayloadCidQuery = gql`
461455
query AppPiecesWithPayloadCidQuery($payloadCid: String!) {
462456
piecesWithPayloadCid(payloadCid: $payloadCid)
@@ -814,7 +808,6 @@ export {
814808
IpniAdEntriesQuery,
815809
IpniAdEntriesCountQuery,
816810
IpniLatestAdQuery,
817-
PiecesWithRootPayloadCidQuery,
818811
PiecesWithPayloadCidQuery,
819812
PieceBuildIndexMutation,
820813
PieceStatusQuery,

0 commit comments

Comments
 (0)