chibenwa commented on code in PR #1849:
URL: https://github.com/apache/james-project/pull/1849#discussion_r1422322876
##########
server/data/data-postgres/src/main/java/org/apache/james/sieve/postgres/PostgresSieveRepository.java:
##########
@@ -100,166 +80,154 @@ private boolean overQuotaAfterModification(long
usedSpace, long size, QuotaSizeL
}
@Override
- public void putScript(Username username, ScriptName name, ScriptContent
content) {
-
transactionRunner.runAndHandleException(Throwing.<EntityManager>consumer(entityManager
-> {
- try {
- haveSpace(username, name, content.length());
- JPASieveScript jpaSieveScript = JPASieveScript.builder()
- .username(username.asString())
- .scriptName(name.getValue())
- .scriptContent(content)
- .build();
- entityManager.persist(jpaSieveScript);
- } catch (QuotaExceededException | StorageException e) {
- rollbackTransactionIfActive(entityManager.getTransaction());
- throw e;
- }
- }).sneakyThrow(), throwStorageExceptionConsumer("Unable to put script
for user " + username.asString()));
+ 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()
Review Comment:
update space after inserting the script, using feedback of the insertion
(`RETURNING` keyword)?
--
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]