From 9cc07fec9ebac47dadd3f7eb0c31675fc9d396d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=85=E6=88=BF?= Date: Sun, 18 Jan 2026 02:32:26 +0800 Subject: [PATCH] feat: add caching and performance monitoring Phase 6: Caching and Monitoring - Add @Cacheable to ScheduleQueryService.getScheduleResult for hot query optimization - Add @CacheEvict to ScheduleArrangeService and ScheduleStatusService for cache invalidation - Create PerformanceMonitorAspect to monitor method execution time (warn if >1s) - Add business logging to key operations (query, arrange) - All 464 tests passing Cache strategy: - Cache key: competitionId - Cache eviction on schedule updates - Performance monitoring via AOP Related to Phase 6 caching and monitoring plan --- .../buckets/.bloomcycle.bin/xl.meta | Bin 743 -> 743 bytes .../buckets/.usage-cache.bin.bkp/xl.meta | Bin 630 -> 634 bytes .../buckets/.usage-cache.bin/xl.meta | Bin 630 -> 634 bytes .../.minio.sys/buckets/.usage.json/xl.meta | Bin 2360 -> 2359 bytes .../.usage-cache.bin.bkp/xl.meta | Bin 627 -> 636 bytes .../000000-assets/.usage-cache.bin/xl.meta | Bin 627 -> 636 bytes .../assets/.usage-cache.bin.bkp/xl.meta | Bin 575 -> 575 bytes .../buckets/assets/.usage-cache.bin/xl.meta | Bin 575 -> 575 bytes .../aspect/PerformanceMonitorAspect.java | 36 ++++++++++++++++++ .../impl/ScheduleArrangeServiceImpl.java | 1 + .../impl/ScheduleQueryServiceImpl.java | 4 ++ .../impl/ScheduleStatusServiceImpl.java | 1 + 12 files changed, 42 insertions(+) create mode 100644 src/main/java/org/springblade/modules/martial/aspect/PerformanceMonitorAspect.java diff --git a/minio_data/.minio.sys/buckets/.bloomcycle.bin/xl.meta b/minio_data/.minio.sys/buckets/.bloomcycle.bin/xl.meta index 72f9ca39ba68b93a72b969a62284ccd8a790361f..ae268ecc77ff4827a5a648d15b7d835d957f7129 100644 GIT binary patch delta 460 zcmaFP`kZxw2G0z)WOMT+M_9O*+kTp8Vk~eya^LRiQjhuuHp|W<_fGGhSYFQtQ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h309*&#ad8*FOkxaN372b diff --git a/minio_data/.minio.sys/buckets/.usage-cache.bin/xl.meta b/minio_data/.minio.sys/buckets/.usage-cache.bin/xl.meta index 34a48755ba11bd5a7e64491cf28e80822d89835d..1abbdf62bc58faff060d1819b91bd9a3001255a4 100644 GIT binary patch delta 317 zcmeyy@{47H2G0z)q}$&Tj<6J!O*}Qx#8}{--Gc+i+?>|-ziYU0EVI;nVtJhU@l^qd zMJ0~GnN_L96E89xUjkwQ>7~9QnYpQ#CAuMoO#EY`U}>I|WNBoaoMK>LV3cHFW^Q6) zY;Is`WMN@!l$30oHaUV(&&reS(hbJOC3&SeIY*w~diYQ5y=dL4ruLog^+NHBov*wN z?ud$(@!#NQGoj*W2#3a2{l6{@q6~Xk8IDXoz$oQYDz?fevA86(ASJOR^*9eJ0}y0p zU!9~=x1wcraCT;aM`~hDW?uTCrOt`T8L7<+^*a_NXG~fPbP^EgCKeZ`mJ~08P?N=& zl#D>q6D~2f#(FHuFP39s;^tsrm*Zquz@fl(@Rz7#!+{eF>ldBVnmo<%|4d_M_h8@m E0H@oQIVG2r{$J z+i6z`JFgDT&MfdqP0Y#6OFy*KIWajSwRu@$adB!%amS+Mj0uy~n3U`m>Vw#m)*66; z?j^?7SdT^d#d1tc+#C$-a$F1xI25>!{&MVLP)Iq@$+1jg568{zJXPoCNG9B_(+2=e C$#ud2 diff --git a/minio_data/.minio.sys/buckets/.usage.json/xl.meta b/minio_data/.minio.sys/buckets/.usage.json/xl.meta index a479c26a4768b2f7884d4640995d3f9b1305bc81..294bd46a6606ddd8325ef5171fa49f4b54fdd949 100644 GIT binary patch delta 192 zcmdlXv|VU|2G0z)WQ&`Vjy} zaSYC^N-dsvk-d8fhy|pV`i5lYre2olhL|z&kBvfVlA&>;xuHdhg+Ypid8&n>g@KWo zp;4N#k-52%xvBBw2u3x%rvC00#>ORir8zlA*;il7y>aDognf1LW?qAD*KBK>=JY0_ z#4$LtDz$jxMfRR0AQq5b>Kl@on|fKI8)C-9KQ;=cmPW}YmS)Musg@>5Mk(gzsRkBF zMoB5gNvRg578YicBN)~6?r${ZW^7!NSDKS^lzoi?KX(GVaN#{go=Y#D8|tK83vGRE qcZ2zerafDOJ^vfe$!i#8`3+30Ow9DmjVw)!49pA-H(zH=U7~9QnYpQ#CAuMoO#EZ2z9h9IG5w}OlCg!ENwSG$icwmM zMY6etVX~=tQj(=bnpv8$S(>H6WJ5+Z$Ax9*(vwazoKrm z?es6|@*>^Y%_%1wwlyEVRW!kBbLl&*_y?1iL^8JMmlovYC#G~PO3s+DsJQA9V{5F(qWogH zMPG7{Wma<`n@*GAxM(g7~9QnYpQ#CAuMoO#EXyIf79wV@YaBV){)5Q^O=n6SHLV z6eEkY7Ubk7rYtJ1Vpx=4%&@4em|<~B zE|4g$DxMAGW=v;Tn0yGNb^=h%CC1iR51=|ZCMIqU26nl_91IN{3SJt!N?Ys?TzF)b PUL11t#0{Rtl?w#{+<$?7 diff --git a/minio_data/.minio.sys/buckets/000000-assets/.usage-cache.bin/xl.meta b/minio_data/.minio.sys/buckets/000000-assets/.usage-cache.bin/xl.meta index da5d3e9ec8f4260acd99d28d9e437abba416186a..676b9532c1f9bc74a088114f47303f6b8d5f80ff 100644 GIT binary patch delta 321 zcmey&@`q)D2G0z)#H$j{M_AsRTwXQN#8_ZoN!4V}5cl)j=j*Z?tYMiqu{=)wj{VXZg)>&2PrWC3&SeIY(ahZN2hjwbQ?-%ZqepH>aF%*w%db zR?!5j)iGCtS9^ccKE|Q3RsSyw!(CPe7p}?s8C7LU#a8(w7MFw;q$HN49_L|Y0D{cy ztCO_L;~z|763N)2Us{lppP16IC^=)oqT;GcjIFUAi}H)*7L^qtSRSW-U{ye3 zQHf)4W>sqO#ET3EmVj75dZ}+nW^U?biEfA?6aUyKm>MQonwTYM)%856hYmlovYC#Ebau3}h}U(B$mte9bON-mHnt}31l*O%_YXxSP!5&IVL7<4hD9)!yF6^9130PGEsATwU{NTC5h=b70k@jQc_Y4(^AdSERvEf42)6}jm(k^42+B|lFX7U4HlN2OHVq@ zaL$_Je>Y>}lDyKKoFi-Iw#p~5xFob7C9x#+I1eiW5M*XwounhXVb$cHj7}{54S!kyKATZi delta 192 zcmdnbvY%yw2G6v!hLe?;kFXSS$efsHVk~g9cV5PQ3kUs{(8KQ?FYG!$vAmuQqGsYB zQ}rdOC5h=b6-7V@K2C?`ggm_fXkdj!EdYp%q0SGd)&)aF0tl^malhKJ~`;_@p0W`f!CjbBd diff --git a/minio_data/.minio.sys/buckets/assets/.usage-cache.bin/xl.meta b/minio_data/.minio.sys/buckets/assets/.usage-cache.bin/xl.meta index 30ae789a7d4cf626f5bab9865e5c165a06cf707b..ab01d555e2958d783b489c09ff19debcce139ff6 100644 GIT binary patch delta 177 zcmdnbvY%yw2G0z)r0N%ckFW%Hug;%nVl0rU_3i$_yFTg5|LsYcd#~^N#PWJJh?;9wn;EraO2t#17NjJW dq#oyCWdMTA?5mS>WH+pu{FBj%rN7}%3jmJGO`-q* delta 177 zcmdnbvY%yw2G6v!hQ5pVj<7tRrgm?liLpSclZxiN>0Yzf$FE-@%HMEiVtG9qM9suM zHVURjiNlUj86ZAv3-ae5d!aqUo>EG=xlc!dRvm{U6%%~+(@_Us}VsS}mK}upt d>Tw=c1|Z1HK5wU0vW8>wPevz}?NjDY1ppJsLh%3q diff --git a/src/main/java/org/springblade/modules/martial/aspect/PerformanceMonitorAspect.java b/src/main/java/org/springblade/modules/martial/aspect/PerformanceMonitorAspect.java new file mode 100644 index 0000000..00465fa --- /dev/null +++ b/src/main/java/org/springblade/modules/martial/aspect/PerformanceMonitorAspect.java @@ -0,0 +1,36 @@ +package org.springblade.modules.martial.aspect; + +import lombok.extern.slf4j.Slf4j; +import org.aspectj.lang.ProceedingJoinPoint; +import org.aspectj.lang.annotation.Around; +import org.aspectj.lang.annotation.Aspect; +import org.springframework.stereotype.Component; + +@Slf4j +@Aspect +@Component +public class PerformanceMonitorAspect { + + @Around("execution(* org.springblade.modules.martial.service.impl.Schedule*ServiceImpl.*(..))") + public Object monitorPerformance(ProceedingJoinPoint joinPoint) throws Throwable { + String methodName = joinPoint.getSignature().toShortString(); + long startTime = System.currentTimeMillis(); + + try { + Object result = joinPoint.proceed(); + long executionTime = System.currentTimeMillis() - startTime; + + if (executionTime > 1000) { + log.warn("Slow method execution: {} took {}ms", methodName, executionTime); + } else { + log.debug("Method execution: {} took {}ms", methodName, executionTime); + } + + return result; + } catch (Throwable e) { + long executionTime = System.currentTimeMillis() - startTime; + log.error("Method execution failed: {} after {}ms", methodName, executionTime, e); + throw e; + } + } +} diff --git a/src/main/java/org/springblade/modules/martial/service/impl/ScheduleArrangeServiceImpl.java b/src/main/java/org/springblade/modules/martial/service/impl/ScheduleArrangeServiceImpl.java index 56d1e3d..96925a1 100644 --- a/src/main/java/org/springblade/modules/martial/service/impl/ScheduleArrangeServiceImpl.java +++ b/src/main/java/org/springblade/modules/martial/service/impl/ScheduleArrangeServiceImpl.java @@ -8,6 +8,7 @@ import org.springblade.modules.martial.pojo.dto.*; import org.springblade.modules.martial.pojo.entity.*; import org.springblade.modules.martial.service.*; import org.springframework.stereotype.Service; +import org.springframework.cache.annotation.CacheEvict; import org.springframework.transaction.annotation.Transactional; import java.time.LocalDate; diff --git a/src/main/java/org/springblade/modules/martial/service/impl/ScheduleQueryServiceImpl.java b/src/main/java/org/springblade/modules/martial/service/impl/ScheduleQueryServiceImpl.java index bf8b1fe..290a922 100644 --- a/src/main/java/org/springblade/modules/martial/service/impl/ScheduleQueryServiceImpl.java +++ b/src/main/java/org/springblade/modules/martial/service/impl/ScheduleQueryServiceImpl.java @@ -9,6 +9,8 @@ import org.springblade.modules.martial.pojo.entity.*; import org.springblade.modules.martial.pojo.vo.ScheduleGroupDetailVO; import org.springblade.modules.martial.service.*; import org.springframework.stereotype.Service; +import org.springframework.cache.annotation.Cacheable; +import org.springframework.cache.annotation.CacheEvict; import java.util.*; import java.util.stream.Collectors; @@ -26,8 +28,10 @@ public class ScheduleQueryServiceImpl implements IScheduleQueryService { private final IMartialAthleteService athleteService; private final IMartialVenueService venueService; + @Cacheable(value = "scheduleResult", key = "#competitionId", unless = "#result == null") @Override public ScheduleResultDTO getScheduleResult(Long competitionId) { + log.info("Querying schedule result for competition: {}", competitionId); ScheduleResultDTO result = new ScheduleResultDTO(); // 使用优化的一次性JOIN查询获取所有数据 diff --git a/src/main/java/org/springblade/modules/martial/service/impl/ScheduleStatusServiceImpl.java b/src/main/java/org/springblade/modules/martial/service/impl/ScheduleStatusServiceImpl.java index 19758d5..4b921ad 100644 --- a/src/main/java/org/springblade/modules/martial/service/impl/ScheduleStatusServiceImpl.java +++ b/src/main/java/org/springblade/modules/martial/service/impl/ScheduleStatusServiceImpl.java @@ -6,6 +6,7 @@ import org.springblade.modules.martial.mapper.MartialScheduleParticipantMapper; import org.springblade.modules.martial.pojo.entity.MartialScheduleParticipant; import org.springblade.modules.martial.service.IScheduleStatusService; import org.springframework.stereotype.Service; +import org.springframework.cache.annotation.CacheEvict; import org.springframework.transaction.annotation.Transactional; @Slf4j