Skip to content

Commit

Permalink
Merge pull request #63 from goverland-labs/feature/votes_search
Browse files Browse the repository at this point in the history
Search for votes.
  • Loading branch information
kazharski authored Jul 22, 2024
2 parents 76db842 + 20ada83 commit 19854b2
Show file tree
Hide file tree
Showing 7 changed files with 182 additions and 156 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

## [0.1.22] - 2024-07-22

### Added
- Search for votes

## [0.1.21] - 2024-07-06

### Changed
Expand Down
8 changes: 8 additions & 0 deletions internal/vote/filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,11 @@ type ExcludeVoterFilter struct {
func (f ExcludeVoterFilter) Apply(db *gorm.DB) *gorm.DB {
return db.Where("voter != ?", f.Voter)
}

type NameFilter struct {
Name string
}

func (f NameFilter) Apply(db *gorm.DB) *gorm.DB {
return db.Where("voter = ? or ens_name = ?", f.Name, f.Name)
}
4 changes: 4 additions & 0 deletions internal/vote/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ func (s *Server) GetVotes(_ context.Context, req *storagepb.VotesFilterRequest)
filters = append(filters, VoterFilter{Voter: req.GetVoter()})
}

if req.GetName() != "" {
filters = append(filters, NameFilter{Name: req.GetName()})
}

list, err := s.sp.GetByFilters(filters, limit, offset, req.GetOrderByVoter())
if err != nil {
log.Error().Err(err).Msgf("get votes by filter: %+v", req)
Expand Down
288 changes: 149 additions & 139 deletions protocol/storagepb/vote.pb.go

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions protocol/storagepb/vote.proto
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ message VotesFilterRequest {
repeated string proposal_ids = 1;
optional string voter = 2;
optional string order_by_voter = 3;
optional uint64 limit = 4;
optional uint64 offset = 5;
optional string name = 4;
optional uint64 limit = 5;
optional uint64 offset = 6;
}

message VoteInfo {
Expand Down
23 changes: 9 additions & 14 deletions protocol/storagepb/vote_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion resources/V9_db_speed_up_votes.sql
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
create index votes_proposal_vp_idx
on votes (proposal_id, vp);
on votes (proposal_id, vp);

create index votes_proposal_ens_idx
on votes (proposal_id, ens_name);

0 comments on commit 19854b2

Please sign in to comment.