Arsnael commented on code in PR #1849:
URL: https://github.com/apache/james-project/pull/1849#discussion_r1423688349
##########
server/data/data-postgres/src/main/java/org/apache/james/sieve/postgres/PostgresSieveRepository.java:
##########
@@ -58,42 +58,24 @@ public PostgresSieveRepository(PostgresSieveQuotaDAO
postgresSieveQuotaDAO,
@Override
public void haveSpace(Username username, ScriptName name, long size)
throws QuotaExceededException {
- reThrowQuotaExceededException(() ->
spaceThatWillBeUsedByNewScript(username, name, size)
- .flatMap(sizeDifference -> throwOnOverQuota(username,
sizeDifference))
- .block());
- }
-
- private void reThrowQuotaExceededException(Runnable runnable) throws
QuotaExceededException {
- try {
- runnable.run();
- } catch (RuntimeException e) {
- if (e.getCause() instanceof QuotaExceededException) {
- throw (QuotaExceededException) e.getCause();
- }
- }
- }
-
- private boolean overQuotaAfterModification(long usedSpace, long size,
QuotaSizeLimit quota) {
- return QuotaSizeUsage.size(usedSpace)
- .add(size)
- .exceedLimit(quota);
+ long sizeDifference = spaceThatWillBeUsedByNewScript(username, name,
size).block();
+ throwOnOverQuota(username, sizeDifference);
}
@Override
public void putScript(Username username, ScriptName name, ScriptContent
content) throws QuotaExceededException {
- reThrowQuotaExceededException(() ->
spaceThatWillBeUsedByNewScript(username, name, content.length())
- .flatMap(spaceToUse -> throwOnOverQuota(username, spaceToUse)
- .thenEmpty(Flux.merge(
- updateSpaceUsed(username, spaceToUse),
-
postgresSieveScriptDAO.upsertScript(PostgresSieveScript.builder()
- .username(username.asString())
- .scriptName(name.getValue())
- .scriptContent(content.getValue())
- .scriptSize(content.length())
- .isActive(false)
- .build()))
- .then()))
- .block());
+ long sizeDifference = spaceThatWillBeUsedByNewScript(username, name,
content.length()).block();
+ throwOnOverQuota(username, sizeDifference);
Review Comment:
why not calling haveSpace that has the exact same two lines then? And make
the function return the space of the script?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]