Skip to content

Commit

Permalink
PR comment fixes
Browse files Browse the repository at this point in the history
Add a fetchByScore signature that doesn't take any arguments and fetches
the first 8192 elements of a leaderboard.

Comment fixes.
  • Loading branch information
nand4011 committed Jan 15, 2025
1 parent ab732c7 commit d906b46
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public void fetchByScoreHappyPath() {
.isInstanceOf(UpsertResponse.Success.class);

// ascending
assertThat(leaderboard.fetchByScore(null, null, SortOrder.ASCENDING))
assertThat(leaderboard.fetchByScore())
.succeedsWithin(FIVE_SECONDS)
.asInstanceOf(InstanceOfAssertFactories.type(FetchResponse.Success.class))
.satisfies(
Expand Down
21 changes: 15 additions & 6 deletions momento-sdk/src/main/java/momento/sdk/ILeaderboard.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
public interface ILeaderboard {

/**
* Updates elements in a leaderboard or inserts elements if they do not already exist. The
* Update elements in a leaderboard or insert elements if they do not already exist. The
* leaderboard is also created if it does not already exist. Note: can upsert a maximum of 8192
* elements at a time.
*
Expand Down Expand Up @@ -63,6 +63,14 @@ CompletableFuture<FetchResponse> fetchByScore(
CompletableFuture<FetchResponse> fetchByScore(
@Nullable Double minScore, @Nullable Double maxScore, @Nullable SortOrder order);

/**
* Fetch the first 8192 elements of the leaderboard, sorted by score ascending.
*
* @return A future containing the result of the fetch operation: {@link FetchResponse.Success}
* containing the elements, or {@link FetchResponse.Error}.
*/
CompletableFuture<FetchResponse> fetchByScore();

/**
* Fetch the elements of the leaderboard by index (rank). Note: can fetch a maximum of 8192
* elements at a time and rank is 0-based (index begins at 0).
Expand All @@ -81,19 +89,20 @@ CompletableFuture<FetchResponse> fetchByRank(
int startRank, int endRank, @Nullable SortOrder order);

/**
* Looks up the rank of the given elements in the leaderboard. The returned elements will be
* sorted numerically by their IDs. Note: rank is 0-based (index begins at 0).
* Look up the rank of the given elements in the leaderboard. The returned elements will be sorted
* numerically by their IDs. Note: rank is 0-based (index begins at 0).
*
* @param ids The IDs of the elements to fetch from the leaderboard.
* @param order The order to fetch the elements in. Defaults to {@link SortOrder#ASCENDING}.
* @param order The rank order to fetch the elements in, based on their scores. Defaults to {@link
* SortOrder#ASCENDING}.
* @return A future containing the result of the fetch operation: {@link FetchResponse.Success}
* containing the elements, or {@link FetchResponse.Error}.
*/
CompletableFuture<FetchResponse> getRank(
@Nonnull Iterable<Integer> ids, @Nullable SortOrder order);

/**
* Fetches the length (number of items) of the leaderboard.
* Fetch the length (number of items) of the leaderboard.
*
* @return A future containing the result of the length operation: {@link LengthResponse.Success}
* containing the length of the leaderboard, or {@link LengthResponse.Error}.
Expand All @@ -111,7 +120,7 @@ CompletableFuture<FetchResponse> getRank(
CompletableFuture<RemoveElementsResponse> removeElements(@Nonnull Iterable<Integer> ids);

/**
* Deletes all elements in the leaderboard.
* Delete all elements in the leaderboard.
*
* @return A future containing the result of the delete operation: {@link DeleteResponse.Success},
* or {@link DeleteResponse.Error}.
Expand Down
6 changes: 6 additions & 0 deletions momento-sdk/src/main/java/momento/sdk/Leaderboard.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ public CompletableFuture<FetchResponse> fetchByScore(
cacheName, leaderboardName, minScore, maxScore, order, null, null);
}

@Override
public CompletableFuture<FetchResponse> fetchByScore() {
return leaderboardDataClient.fetchByScore(
cacheName, leaderboardName, null, null, null, null, null);
}

@Override
public CompletableFuture<FetchResponse> fetchByRank(
int startRank, int endRank, @Nullable SortOrder order) {
Expand Down

0 comments on commit d906b46

Please sign in to comment.