1313
1414logger : logging .Logger = logging .getLogger (__name__ )
1515
16+ # Track last reconciled quota values to avoid DB updates when quota is unchanged
17+ _last_reconciled_quotas : dict [str , int ] = {}
18+
1619
1720INCREASE_QUOTA_STATEMENT = """
1821 UPDATE quota_limits
@@ -186,6 +189,12 @@ def reconcile_quota_limits(
186189 logger .debug ("No initial quota set for '%s', skipping reconciliation" , name )
187190 return
188191
192+ # Check if quota value has changed since last reconciliation, to remove redundant checks
193+ new_quota = quota_limiter .initial_quota
194+ if name in _last_reconciled_quotas and _last_reconciled_quotas [name ] == new_quota :
195+ logger .debug ("Quota unchanged for '%s' (value=%d), skipping reconciliation" , name , new_quota )
196+ return
197+
189198 # Select appropriate SQL based on limiter type
190199 if quota_limiter .type == constants .USER_QUOTA_LIMITER :
191200 reconcile_sql = RECONCILE_USER_QUOTA_LIMITS_STATEMENT
@@ -199,8 +208,6 @@ def reconcile_quota_limits(
199208 )
200209 return
201210
202- new_quota = quota_limiter .initial_quota
203-
204211 try :
205212 with connection .cursor () as cursor :
206213 cursor .execute (
@@ -237,6 +244,9 @@ def reconcile_quota_limits(
237244 "(no records or all match current configuration)" ,
238245 name ,
239246 )
247+
248+ # Tracking quota value
249+ _last_reconciled_quotas [name ] = new_quota
240250 except Exception as e :
241251 logger .error (
242252 "Failed to reconcile quota limits for '%s': %s" ,
0 commit comments