Skip to content

Commit

Permalink
Change rich list endpoint to only return the latest rich list.
Browse files Browse the repository at this point in the history
  • Loading branch information
LINCKODE committed Aug 2, 2024
1 parent bfd60cc commit 61c357c
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 75 deletions.
61 changes: 30 additions & 31 deletions api/protobuff/stats-api.pb.go

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

42 changes: 4 additions & 38 deletions api/protobuff/stats-api.pb.gw.go

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

8 changes: 4 additions & 4 deletions api/protobuff/stats-api.proto
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ message RichList {
}

message GetRichListSliceRequest {
string epoch = 1;
int32 page = 2;
int32 page = 1;

}
message GetRichListSliceResponse {
Pagination pagination = 1;
RichList rich_list = 2;
uint32 epoch = 2;
RichList rich_list = 3;
}


Expand All @@ -67,7 +67,7 @@ service StatsService {

rpc GetRichListSlice(GetRichListSliceRequest) returns (GetRichListSliceResponse) {
option (google.api.http) = {
get: "/v1/epochs/{epoch}/rich-list"
get: "/v1/rich-list"
};
};

Expand Down
9 changes: 7 additions & 2 deletions api/rpc/rpc_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"log"
"net"
"net/http"
"strconv"
)

type Server struct {
Expand Down Expand Up @@ -65,7 +66,10 @@ func (s *Server) GetRichListSlice(ctx context.Context, request *protobuff.GetRic
page = 1
}

data := s.cache.GetEpochPaginationData(request.Epoch)
epoch := s.cache.GetQubicData().Epoch
epochString := strconv.Itoa(int(epoch))

data := s.cache.GetEpochPaginationData(epochString)

if data == cache.EmptyPaginationData {
return nil, status.Errorf(codes.NotFound, "could not find the rich list for the specified epoch")
Expand All @@ -79,7 +83,7 @@ func (s *Server) GetRichListSlice(ctx context.Context, request *protobuff.GetRic
}
start := (page - 1) * s.richListPageSize

collection := s.dbClient.Database(s.mongoDatabase).Collection(s.mongoRichListCollection + "_" + request.Epoch)
collection := s.dbClient.Database(s.mongoDatabase).Collection(s.mongoRichListCollection + "_" + epochString)
findOptions := options.Find().SetSkip(int64(start)).SetLimit(int64(s.richListPageSize)).SetSort(bson.D{{"balance", -1}})

cursor, err := collection.Find(ctx, bson.D{{}}, findOptions)
Expand Down Expand Up @@ -108,6 +112,7 @@ func (s *Server) GetRichListSlice(ctx context.Context, request *protobuff.GetRic
TotalPages: lastPage,
TotalRecords: totalRecords,
},
Epoch: epoch,
RichList: &protobuff.RichList{
Entities: list,
},
Expand Down

0 comments on commit 61c357c

Please sign in to comment.