Skip to content

Commit

Permalink
fix: remove payloadRootCid lookup (#1721)
Browse files Browse the repository at this point in the history
* remove payloadRootCid lookup

* refactor the if
  • Loading branch information
LexLuthr authored Sep 26, 2023
1 parent 946fc34 commit 71eff92
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 63 deletions.
33 changes: 0 additions & 33 deletions gql/resolver_piece.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 0 additions & 3 deletions gql/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -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!]!

Expand Down
27 changes: 7 additions & 20 deletions react/src/LID.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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]
}
}

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

if ((pieceRes || {}).loading || (payloadRes || {}).loading || (rootPayloadRes || {}).loading) {
if ((pieceRes || {}).loading || (payloadRes || {}).loading) {
return <div>Loading ...</div>
}

Expand Down
7 changes: 0 additions & 7 deletions react/src/gql.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -814,7 +808,6 @@ export {
IpniAdEntriesQuery,
IpniAdEntriesCountQuery,
IpniLatestAdQuery,
PiecesWithRootPayloadCidQuery,
PiecesWithPayloadCidQuery,
PieceBuildIndexMutation,
PieceStatusQuery,
Expand Down

0 comments on commit 71eff92

Please sign in to comment.