@@ -170,36 +170,32 @@ public CreateAttemptResponse createAttempt(Long userId, CreateAttemptRequest req
170170
171171 activeSession .setAttemptedCount (activeSession .getAttemptedCount () + 1 );
172172
173-
174173 Integer srGained = 0 ;
175174 Integer currentSr = user .getSr ();
176175
177176 if (request .getSuccess ()) {
178177 activeSession .setCompletedCount (activeSession .getCompletedCount () + 1 );
179178 try {
180- LevelSRReward reward = LevelSRReward .fromLevelName (mission .getDifficulty ());
181- srGained = reward .getSrReward ();
182-
183- Integer srBefore = user .getSr ();
184- Integer srAfter = srBefore + srGained ;
179+ int gained = LevelSRReward .fromLevelName (mission .getDifficulty ()).getSrReward ();
185180
186- user .updateSr (srAfter );
187- currentSr = srAfter ;
181+ int sessionGain = (activeSession .getSrGained () == null ? 0 : activeSession .getSrGained ());
182+ int before = user .getSr () + sessionGain ;
183+ int after = before + gained ;
188184
189- activeSession .setSrGained (activeSession . getSrGained () + srGained );
185+ activeSession .setSrGained (sessionGain + gained );
190186
191- SRHistory srHistory = SRHistory .builder ()
187+ srHistoryRepository . save ( SRHistory .builder ()
192188 .user (user )
193189 .session (activeSession )
194190 .mission (mission )
195- .srBefore (srBefore )
196- .srAfter (srAfter )
197- .build ();
191+ .srBefore (before )
192+ .srAfter (after )
193+ .build ()) ;
198194
199- srHistoryRepository . save ( srHistory ) ;
195+ srGained = gained ;
200196
201- log .info ("SR updated for user: {} from {} to {} (+{}) for difficulty: {}" ,
202- userId , srBefore , srAfter , srGained , mission .getDifficulty ());
197+ log .info ("SR pending (session accumulate): user={}, +{}, difficulty={}, sessionId= {}" ,
198+ userId , srGained , mission .getDifficulty (), activeSession . getId ());
203199 } catch (IllegalArgumentException e ) {
204200 log .warn ("Invalid difficulty level: {} for mission: {}" , mission .getDifficulty (), mission .getId ());
205201 throw new ValidationException (ErrorCode .INVALID_DIFFICULTY_LEVEL , mission .getDifficulty ());
0 commit comments