Skip to content

Commit

Permalink
fixed caching issue when adding/removing spaces on multiple hosts beh…
Browse files Browse the repository at this point in the history
…ind load balancer
  • Loading branch information
albogdano committed Nov 8, 2023
1 parent bc5f91d commit dcc814e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ public String addSpace(@RequestParam String space,
authUser.getSpaces().add(spaceObj.getId() + Para.getConfig().separator() + spaceObj.getName());
authUser.update();
model.addAttribute("space", spaceObj);
utils.getAllSpaces().add(spaceObj);
utils.getAllSpacesAdmin().add(spaceObj);
} else {
model.addAttribute("error", Collections.singletonMap("name", utils.getLang(req).get("posts.error1")));
}
Expand All @@ -206,7 +206,7 @@ public String removeSpace(@RequestParam String space, HttpServletRequest req, Ht
pc.delete(s);
authUser.getSpaces().remove(space);
authUser.update();
utils.getAllSpaces().remove(s);
utils.getAllSpacesAdmin().remove(s);
}
if (utils.isAjaxRequest(req)) {
res.setStatus(200);
Expand Down Expand Up @@ -260,7 +260,7 @@ public String renameSpace(@RequestParam String space,

s.addProperty("posts_need_approval", needsapproval && CONF.postsNeedApproval());
pc.update(s);
utils.getAllSpaces().parallelStream().
utils.getAllSpacesAdmin().parallelStream().
filter(ss -> ss.getId().equals(s.getId())).
forEach(e -> {
e.setName(s.getName());
Expand Down Expand Up @@ -793,7 +793,7 @@ private void updateSOUserAccounts(Map<String, User> accounts2emails) {
}

private List<Sysprop> getSpaces(Pager itemcount) {
Set<Sysprop> spaces = utils.getAllSpaces();
Set<Sysprop> spaces = utils.getAllSpacesAdmin();
itemcount.setCount(spaces.size());
LinkedList<Sysprop> list = new LinkedList<>(spaces.stream().
filter(s -> !utils.isDefaultSpace(s.getName())).collect(Collectors.toList()));
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/com/erudika/scoold/utils/ScooldUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -1339,6 +1339,13 @@ public Set<Sysprop> getAllSpaces() {
return allSpaces;
}

public Set<Sysprop> getAllSpacesAdmin() {
if (allSpaces == null || pc.getCount("scooldspace").intValue() != allSpaces.size()) { // caching issue on >1 nodes
allSpaces = new LinkedHashSet<>(pc.findQuery("scooldspace", "*", new Pager(Config.DEFAULT_LIMIT)));
}
return allSpaces;
}

public boolean canAccessSpace(Profile authUser, String targetSpaceId) {
if (authUser == null) {
return isDefaultSpacePublic() && isDefaultSpace(targetSpaceId);
Expand Down

0 comments on commit dcc814e

Please sign in to comment.