Skip to content

Commit

Permalink
feat: Increase max iterations prevent endless loops
Browse files Browse the repository at this point in the history
  • Loading branch information
pangdayuan1 committed Dec 23, 2024
1 parent 7cfdbbd commit 0c32f31
Showing 1 changed file with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class ScenePoolService {
private static final int DEFAULT_LIMIT = 200;
private static final String CLEAR_LIMIT_KEY = "clear.pool.limit";
private static final int MAX_PAGE_SIZE = 300;
private static final int MAX_ITERATIONS = 200;

public long clearPoolByApp(String appId, String providerName) {
ScenePoolProvider provider = scenePoolFactory.getProvider(providerName);
Expand All @@ -35,14 +36,25 @@ public long clearPoolByApp(String appId, String providerName) {
long totalDeletedCount = 0;
Date date = new Date();
long deletedCount;
int iterations = 0;

do {
deletedCount = provider.clearSceneByAppid(appId, date, limit);
totalDeletedCount += deletedCount;
} while (deletedCount == limit);
iterations++;
} while (deletedCount == limit && iterations < MAX_ITERATIONS);

return totalDeletedCount;
}

private int getLimit() {
int limit = defaultApplicationConfig.getConfigAsInt(CLEAR_LIMIT_KEY, DEFAULT_LIMIT);
if (limit == 0) {
return DEFAULT_LIMIT;
}
return limit;
}

public AREXMocker findByRecordId(String recordId, MockCategoryType categoryType) {
if (StringUtils.isEmpty(recordId)) {
return null;
Expand Down

0 comments on commit 0c32f31

Please sign in to comment.