@@ -36,6 +36,9 @@ public class SoptampUserService {
3636 @ Value ("${makers.app.soptamp.appjam-mode:false}" )
3737 private boolean appjamMode ;
3838
39+ @ Value ("${sopt.current.generation}" )
40+ private Long currentGeneration ;
41+
3942 /* ==================== 조회/프로필 ==================== */
4043
4144 @ Transactional (readOnly = true )
@@ -50,7 +53,7 @@ public SoptampUserInfo editProfileMessage(Long userId, String profileMessage) {
5053 SoptampUser soptampUser = soptampUserRepository .findByUserId (userId )
5154 .orElseThrow (() -> new BadRequestException (ErrorCode .USER_NOT_FOUND ));
5255 soptampUser .updateProfileMessage (profileMessage );
53- eventPublisher . raise ( SoptampUserProfileCacheSyncEvent . of ( userId ) );
56+ this . raiseProfileCacheSyncEvent ( soptampUser );
5457 return SoptampUserInfo .of (soptampUser );
5558 }
5659
@@ -95,9 +98,8 @@ private void upsertSoptampUserNormal(PlatformUserInfoResponse profile, Long user
9598
9699 private void updateSoptampUserNormal (SoptampUser registeredUser , PlatformUserInfoResponse profile ,
97100 PlatformUserInfoResponse .SoptActivities latest ) {
98- Long userId = registeredUser .getUserId ();
99101 String part = latest .part () == null ? "미상" : latest .part ();
100- String newNickname = generatePartBasedUniqueNickname (profile .name (), part , userId );
102+ String newNickname = generatePartBasedUniqueNickname (profile .name (), part , registeredUser . getUserId () );
101103
102104 registeredUser .initTotalPoints ();
103105 registeredUser .updateChangedGenerationInfo (
@@ -106,7 +108,7 @@ private void updateSoptampUserNormal(SoptampUser registeredUser, PlatformUserInf
106108 newNickname
107109 );
108110
109- eventPublisher . raise ( SoptampUserAllCacheSyncEvent . of ( userId ) );
111+ this . raiseAllCacheSyncEvent ( registeredUser );
110112 }
111113
112114 private void createSoptampUserNormal (PlatformUserInfoResponse profile , Long userId ,
@@ -117,7 +119,7 @@ private void createSoptampUserNormal(PlatformUserInfoResponse profile, Long user
117119 SoptampUser newSoptampUser = createNewSoptampUser (userId , uniqueNickname , (long ) profile .lastGeneration (),
118120 findSoptPartByPartName (part ));
119121 soptampUserRepository .save (newSoptampUser );
120- eventPublisher . raise ( SoptampUserAllCacheSyncEvent . of ( userId ) );
122+ this . raiseAllCacheSyncEvent ( newSoptampUser );
121123 }
122124
123125 private boolean isGenerationChanged (SoptampUser registeredUser , Long profileGeneration ) {
@@ -158,7 +160,7 @@ private void upsertSoptampUserForAppjam(PlatformUserInfoResponse profile,
158160
159161 // 앱잼 변환 시점에 한 번 포인트 초기화
160162 registeredUser .initTotalPoints ();
161- eventPublisher . raise ( SoptampEvent . SoptampUserAllCacheSyncEvent . of ( userId ) );
163+ this . raiseAllCacheSyncEvent ( registeredUser );
162164 }
163165
164166 private void createSoptampUserAppjam (PlatformUserInfoResponse profile ,
@@ -183,7 +185,7 @@ private void createSoptampUserAppjam(PlatformUserInfoResponse profile,
183185 newSoptampUser .initTotalPoints (); // 새 시즌이니 0점부터
184186
185187 soptampUserRepository .save (newSoptampUser );
186- eventPublisher . raise ( SoptampUserAllCacheSyncEvent . of ( userId ) );
188+ this . raiseAllCacheSyncEvent ( newSoptampUser );
187189 }
188190
189191 private boolean needsAppjamNicknameMigration (SoptampUser user ) {
@@ -266,9 +268,7 @@ public void addPointByLevel(Long userId, Integer level) {
266268 .orElseThrow (() -> new BadRequestException (ErrorCode .USER_NOT_FOUND ));
267269 soptampUser .addPointsByLevel (level );
268270
269- if (!appjamMode ) {
270- eventPublisher .raise (SoptampUserScoreCacheSyncEvent .of (userId ));
271- }
271+ this .raiseScoreCacheSyncEvent (soptampUser );
272272 }
273273
274274 @ Transactional
@@ -277,9 +277,7 @@ public void subtractPointByLevel(Long userId, Integer level) {
277277 .orElseThrow (() -> new BadRequestException (ErrorCode .USER_NOT_FOUND ));
278278 soptampUser .subtractPointsByLevel (level );
279279
280- if (!appjamMode ) {
281- eventPublisher .raise (SoptampUserScoreCacheSyncEvent .of (userId ));
282- }
280+ this .raiseScoreCacheSyncEvent (soptampUser );
283281 }
284282
285283 @ Transactional
@@ -288,9 +286,7 @@ public void initPoint(Long userId) {
288286 .orElseThrow (() -> new BadRequestException (ErrorCode .USER_NOT_FOUND ));
289287 soptampUser .initTotalPoints ();
290288 soptampUserRepository .save (soptampUser );
291- if (!appjamMode ) {
292- eventPublisher .raise (SoptampUserScoreCacheSyncEvent .of (userId ));
293- }
289+ this .raiseScoreCacheSyncEvent (soptampUser );
294290 }
295291
296292 @ Transactional
@@ -300,7 +296,11 @@ public void initAllSoptampUserPoints() {
300296 soptampUserRepository .saveAll (soptampUserList );
301297 if (!appjamMode ) {
302298 rankCacheService .deleteAll ();
303- rankCacheService .addAll (soptampUserList .stream ().map (SoptampUserInfo ::of ).toList ());
299+ List <SoptampUserInfo > currentGenerationUserInfos = soptampUserList .stream ()
300+ .filter (u -> currentGeneration .equals (u .getGeneration ()))
301+ .map (SoptampUserInfo ::of )
302+ .toList ();
303+ rankCacheService .addAll (currentGenerationUserInfos );
304304 }
305305 }
306306
@@ -310,9 +310,9 @@ public void initSoptampRankCache() {
310310 throw new BadRequestException (ErrorCode .INVALID_APPJAM_SEASON_REQUEST );
311311 }
312312
313- List <SoptampUser > soptampUserList = soptampUserRepository .findAll ( );
313+ List <SoptampUser > currentGenerationUsers = soptampUserRepository .findAllByGeneration ( currentGeneration );
314314 rankCacheService .deleteAll ();
315- rankCacheService .addAll (soptampUserList .stream ().map (SoptampUserInfo ::of ).toList ());
315+ rankCacheService .addAll (currentGenerationUsers .stream ().map (SoptampUserInfo ::of ).toList ());
316316 }
317317
318318 @ Transactional
@@ -325,4 +325,25 @@ public void deleteAllSoptampUsers() {
325325 public void handleUserWithdrawEvent (final UserWithdrawEvent event ) {
326326 soptampUserRepository .deleteByUserId (event .getUserId ());
327327 }
328- }
328+
329+ private void raiseScoreCacheSyncEvent (SoptampUser user ) {
330+ if (appjamMode ) return ;
331+ if (currentGeneration .equals (user .getGeneration ())) {
332+ eventPublisher .raise (SoptampUserScoreCacheSyncEvent .of (user .getUserId ()));
333+ }
334+ }
335+
336+ private void raiseProfileCacheSyncEvent (SoptampUser user ) {
337+ if (appjamMode ) return ;
338+ if (currentGeneration .equals (user .getGeneration ())) {
339+ eventPublisher .raise (SoptampUserProfileCacheSyncEvent .of (user .getUserId ()));
340+ }
341+ }
342+
343+ private void raiseAllCacheSyncEvent (SoptampUser user ) {
344+ if (appjamMode ) return ;
345+ if (currentGeneration .equals (user .getGeneration ())) {
346+ eventPublisher .raise (SoptampUserAllCacheSyncEvent .of (user .getUserId ()));
347+ }
348+ }
349+ }
0 commit comments