Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent unnecessary RBAC users request #567

Merged
merged 1 commit into from
Sep 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ private Uni<List<User>> getWithPagination(Function<Integer, Uni<Page<RbacUser>>>
AtomicInteger::new,
state -> fetcher.apply(state.getAndIncrement())
)
.until(page -> page.getData().isEmpty())
.whilst(page -> page.getData().size() == rbacElementsPerPage)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most of the time, this will prevent one RBAC request per recipients resolution.

See this for details about until and whilst.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's an error in the Javadoc BTW: until stops when the predicates passes (the Javadoc says the opposite).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From reading the Javadoc, whilst() is really what we want.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.onItem().transform(page -> page.getData().stream().map(rbacUser -> {
User user = new User();
user.setUsername(rbacUser.getUsername());
Expand Down
4 changes: 2 additions & 2 deletions backend/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ quarkus.log.cloudwatch.access-key-secret=placeholder

# The current status is cached to limit the number of status DB queries
quarkus.cache.caffeine.maintenance.expire-after-write=PT60s
quarkus.cache.caffeine.rbac-recipient-users-provider-get-users.expire-after-write=PT5M
quarkus.cache.caffeine.rbac-recipient-users-provider-get-group-users.expire-after-write=PT5M
quarkus.cache.caffeine.rbac-recipient-users-provider-get-users.expire-after-write=PT10M
quarkus.cache.caffeine.rbac-recipient-users-provider-get-group-users.expire-after-write=PT10M
Comment on lines +123 to +124
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As suggested by @pilhuhn on Slack yesterday.

Prod is currently caching data for 1 minute (the 5 minute increase hasn't been deployed).


# Period between two event log cleanings. It must be expressed with the ISO-8601 duration format PnDTnHnMn.nS.
event-log-cleaner.period=PT10M
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void getAllUsersFromDefaultGroup() {

@Test
public void getAllUsersCache() {
int initialSize = 95;
int initialSize = 1095;
mockGetUsers(initialSize, false);

List<User> users = rbacRecipientUsersProvider.getUsers(accountId, false).await().indefinitely();
Expand All @@ -65,7 +65,7 @@ public void getAllUsersCache() {
Assertions.assertEquals(String.format("username-%d", i), users.get(i).getUsername());
}

int updatedSize = 323;
int updatedSize = 1323;
mockGetUsers(updatedSize, false);

// Should still have the initial size because of the cache
Expand Down