From b1865d135c52235bc97c8f36fb8de5b00efeaabc Mon Sep 17 00:00:00 2001 From: Ghost_chu Date: Tue, 7 Jan 2025 18:09:49 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BF=99=E4=B8=8B=E5=BA=94=E8=AF=A5=E7=9C=9F?= =?UTF-8?q?=E4=BF=AE=E5=A5=BD=E4=BA=86=E5=90=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../btn/sparkle/module/ping/PingController.java | 15 +++++---------- .../module/userapp/UserApplicationService.java | 5 +++-- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/ghostchu/btn/sparkle/module/ping/PingController.java b/src/main/java/com/ghostchu/btn/sparkle/module/ping/PingController.java index bace699..c0c49e4 100644 --- a/src/main/java/com/ghostchu/btn/sparkle/module/ping/PingController.java +++ b/src/main/java/com/ghostchu/btn/sparkle/module/ping/PingController.java @@ -73,8 +73,7 @@ public class PingController extends SparkleController { @PostMapping("/peers/submit") public ResponseEntity submitPeers(@RequestBody @Validated BtnPeerPing ping) throws AccessDeniedException, UnknownHostException { - var cred = cred(); - userApplicationService.updateUserApplicationLastAccessTime(cred); + var cred = userApplicationService.updateUserApplicationLastAccessTime(cred()); var audit = new LinkedHashMap(); audit.put("appId", cred.getAppId()); if (isCredBanned(cred)) { @@ -95,8 +94,7 @@ public ResponseEntity submitPeers(@RequestBody @Validated BtnPeerPing pi @PostMapping("/histories/submit") public ResponseEntity submitPeerHistories(@RequestBody @Validated BtnPeerHistoryPing ping) throws AccessDeniedException, UnknownHostException { - var cred = cred(); - userApplicationService.updateUserApplicationLastAccessTime(cred); + var cred = userApplicationService.updateUserApplicationLastAccessTime(cred()); var audit = new LinkedHashMap(); audit.put("appId", cred.getAppId()); if (isCredBanned(cred)) { @@ -117,8 +115,7 @@ public ResponseEntity submitPeerHistories(@RequestBody @Validated BtnPee @PostMapping("/bans/submit") public ResponseEntity submitBans(@RequestBody @Validated BtnBanPing ping) throws AccessDeniedException, UnknownHostException { - var cred = cred(); - userApplicationService.updateUserApplicationLastAccessTime(cred); + var cred = userApplicationService.updateUserApplicationLastAccessTime(cred()); var audit = new LinkedHashMap(); audit.put("appId", cred.getAppId()); if (isCredBanned(cred)) { @@ -138,8 +135,7 @@ public ResponseEntity submitBans(@RequestBody @Validated BtnBanPing ping @GetMapping("/config") public ResponseEntity config() throws AccessDeniedException, JsonProcessingException, UnknownHostException { - var cred = cred(); - userApplicationService.updateUserApplicationLastAccessTime(cred); + var cred = userApplicationService.updateUserApplicationLastAccessTime(cred()); var audit = new LinkedHashMap(); audit.put("appId", cred.getAppId()); if (isCredBanned(cred)) { @@ -173,8 +169,7 @@ public ResponseEntity config() throws AccessDeniedException, JsonProcess @GetMapping("/rules/retrieve") public ResponseEntity rule() throws IOException, AccessDeniedException { - var cred = cred(); - userApplicationService.updateUserApplicationLastAccessTime(cred); + var cred = userApplicationService.updateUserApplicationLastAccessTime(cred()); var audit = new LinkedHashMap(); audit.put("appId", cred.getAppId()); if (isCredBanned(cred)) { diff --git a/src/main/java/com/ghostchu/btn/sparkle/module/userapp/UserApplicationService.java b/src/main/java/com/ghostchu/btn/sparkle/module/userapp/UserApplicationService.java index 0b43119..a238a91 100644 --- a/src/main/java/com/ghostchu/btn/sparkle/module/userapp/UserApplicationService.java +++ b/src/main/java/com/ghostchu/btn/sparkle/module/userapp/UserApplicationService.java @@ -123,13 +123,14 @@ public UserApplication editUserApplicationComment(Long id, String comment) throw @Transactional(Transactional.TxType.NOT_SUPPORTED) @Lock(value = LockModeType.OPTIMISTIC) @Retryable(retryFor = ObjectOptimisticLockingFailureException.class, backoff = @Backoff(delay = 100, multiplier = 2)) - public void updateUserApplicationLastAccessTime(UserApplication userApplication) { + public UserApplication updateUserApplicationLastAccessTime(UserApplication userApplication) { userApplication.setLastAccessAt(OffsetDateTime.now()); try { - userApplicationRepository.save(userApplication); + return userApplicationRepository.save(userApplication); } catch (Exception e) { log.info("Failed to update last access time for user application: {}", userApplication.getId(), e); } + return userApplication; } public UserApplicationDto toDto(UserApplication userApplication) {