Skip to content

Commit

Permalink
Merge pull request #1532 from mysteriumnetwork/mobile-proposal-filter
Browse files Browse the repository at this point in the history
Filter proposals using query params instead of post-filtering result
  • Loading branch information
tadaskay authored Jan 17, 2020
2 parents 25675f0 + e0360e5 commit c2cc5bd
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 16 deletions.
12 changes: 1 addition & 11 deletions core/discovery/apidiscovery/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,5 @@ func (a *apiRepository) Proposal(id market.ProposalID) (*market.ServiceProposal,

// Proposals returns proposals matching filter.
func (a *apiRepository) Proposals(filter *proposal.Filter) ([]market.ServiceProposal, error) {
proposals, err := a.discoveryAPI.Proposals()
if err != nil {
return nil, err
}
var filtered []market.ServiceProposal
for _, p := range proposals {
if filter.Matches(p) {
filtered = append(filtered, p)
}
}
return filtered, nil
return a.discoveryAPI.QueryProposals(filter.ToAPIQuery())
}
6 changes: 5 additions & 1 deletion core/discovery/proposal/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,14 @@ func (filter *Filter) Matches(proposal market.ServiceProposal) bool {

// ToAPIQuery serialises filter to query of Mysterium API
func (filter *Filter) ToAPIQuery() mysterium.ProposalsQuery {
return mysterium.ProposalsQuery{
query := mysterium.ProposalsQuery{
NodeKey: filter.ProviderID,
ServiceType: filter.ServiceType,
AccessPolicyID: filter.AccessPolicyID,
AccessPolicySource: filter.AccessPolicySource,
}
if filter.ServiceType == "" {
query.ServiceType = "all"
}
return query
}
2 changes: 1 addition & 1 deletion e2e/connection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func TestConsumerConnectsToProvider(t *testing.T) {

if i != len(servicesInFlag)-1 {
// this allows the nats to reconnect properly before starting a new service test
time.Sleep(time.Second * 5)
time.Sleep(time.Second * 10)
}
}
})
Expand Down
4 changes: 1 addition & 3 deletions mobile/mysterium/proposals_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,7 @@ func (m *proposalsManager) getFromCache() []market.ServiceProposal {
}

func (m *proposalsManager) getFromRepository() ([]market.ServiceProposal, error) {
allProposals, err := m.repository.Proposals(&proposal.Filter{
ServiceType: "all",
})
allProposals, err := m.repository.Proposals(&proposal.Filter{})
if err != nil {
return nil, err
}
Expand Down

0 comments on commit c2cc5bd

Please sign in to comment.