diff --git a/src/main/java/xyz/thewhitedog9487/WebAPI/Controller/Filter/LogClientInfo.java b/src/main/java/xyz/thewhitedog9487/WebAPI/Controller/Filter/LogClientInfo.java index f91ab28..e5fe485 100644 --- a/src/main/java/xyz/thewhitedog9487/WebAPI/Controller/Filter/LogClientInfo.java +++ b/src/main/java/xyz/thewhitedog9487/WebAPI/Controller/Filter/LogClientInfo.java @@ -15,6 +15,7 @@ import java.time.Instant; import java.util.Collections; import java.util.List; import java.util.Locale; +import java.util.concurrent.locks.Lock; @Slf4j @Component @@ -26,6 +27,7 @@ public class LogClientInfo implements Filter { "/accesslog"); @Autowired AccessLogRepository AccessLogRepository; + @Autowired Lock SQLiteWriteLock; @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { @@ -54,12 +56,16 @@ public class LogClientInfo implements Filter { Instant.now(), null, null ); + SQLiteWriteLock.lock(); Log = AccessLogRepository.save(Log); + SQLiteWriteLock.unlock(); chain.doFilter(request, Response); var ResponseBody = IgnorePaths.stream() .anyMatch( path -> HttpServletRequest.getRequestURI().startsWith(path) ) ? null : new String( Response.getContentAsByteArray(), Response.getCharacterEncoding() ); Log.setResponseStatusCode(HttpServletResponse.getStatus()); Log.setResponseBody(ResponseBody); + SQLiteWriteLock.lock(); AccessLogRepository.save(Log); + SQLiteWriteLock.unlock(); Response.copyBodyToResponse(); } } \ No newline at end of file diff --git a/src/main/java/xyz/thewhitedog9487/WebAPI/GlobalSharedBean.java b/src/main/java/xyz/thewhitedog9487/WebAPI/GlobalSharedBean.java index 95dbb27..d1eec4d 100644 --- a/src/main/java/xyz/thewhitedog9487/WebAPI/GlobalSharedBean.java +++ b/src/main/java/xyz/thewhitedog9487/WebAPI/GlobalSharedBean.java @@ -13,6 +13,8 @@ import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.util.List; +import java.util.concurrent.locks.Lock; +import java.util.concurrent.locks.ReentrantLock; @Slf4j @Component @@ -50,4 +52,8 @@ class GlobalSharedBean { @Bean ApiKeyAuthenticationFilter ApiKeyAuthenticationFilter(){ return new ApiKeyAuthenticationFilter(); } + + @Bean + Lock SQLiteWriteLock(){ + return new ReentrantLock(); } }