Skip to content
This repository has been archived by the owner on May 16, 2023. It is now read-only.

Commit

Permalink
Merge pull request #33 from corona-warn-app/feat/user-agent-logging
Browse files Browse the repository at this point in the history
Feat: Improve User Agent Logging
  • Loading branch information
f11h authored Apr 13, 2022
2 parents ff8ce77 + a8c4b65 commit 7e3d444
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ public interface UserAgentLogRepository extends JpaRepository<UserAgentLogEntity
Optional<UserAgentLogEntity> getFirstByTimestampAndUserAgentAndAndRequestString(
ZonedDateTime timestamp, String userAgent, String requestString);

@Query("UPDATE UserAgentLogEntity e SET e.count = :count WHERE e.id = :id")
@Modifying
int updateCount(@Param("id") Long id, @Param("count") Long count);

@Query("DELETE FROM UserAgentLogEntity e WHERE e.timestamp < :threshold")
@Modifying
int cleanup(@Param("threshold") ZonedDateTime threshold);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ public void increaseCount(ZonedDateTime timestamp, String userAgent, String requ
if (existingEntityOptional.isPresent()) {
log.debug("Entity for K/V Pair already exists, increasing count.");
UserAgentLogEntity existingEntity = existingEntityOptional.get();
existingEntity.setCount(existingEntity.getCount() + amount);
userAgentLogRepository.save(existingEntity);
userAgentLogRepository.updateCount(existingEntity.getId(), existingEntity.getCount() + amount);
} else {
log.debug("Entity for K/V Pair does not exist, creating new one.");
userAgentLogRepository.save(
Expand All @@ -69,6 +68,7 @@ public void increaseCount(ZonedDateTime timestamp, String userAgent, String requ
* @param threshold Threshold timestamp
* @return Number of deleted entities
*/
@Transactional
public int cleanup(ZonedDateTime threshold) {
return userAgentLogRepository.cleanup(threshold);
}
Expand Down

0 comments on commit 7e3d444

Please sign in to comment.