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 24, 2024
2 parents 0c32f31 + c5eaeed commit e662080
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public <T extends Mocker> boolean saveRecord(@NotNull T item) {
}

mockResultProvider.calculateEigen(item);
item.setCreationTime(System.currentTimeMillis());
RepositoryProvider<T> repositoryWriter = repositoryProviderFactory.defaultProvider();
return repositoryWriter != null && repositoryWriter.save(item);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ public class ScenePoolService {
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;
private static final int MAX_LIMIT = 5000;
private static final int MIN_LIMIT = 0;

public long clearPoolByApp(String appId, String providerName) {
ScenePoolProvider provider = scenePoolFactory.getProvider(providerName);

int limit = defaultApplicationConfig.getConfigAsInt(CLEAR_LIMIT_KEY, DEFAULT_LIMIT);
int limit = getLimit();
long totalDeletedCount = 0;
Date date = new Date();
long deletedCount;
Expand All @@ -42,15 +44,17 @@ public long clearPoolByApp(String appId, String providerName) {
deletedCount = provider.clearSceneByAppid(appId, date, limit);
totalDeletedCount += deletedCount;
iterations++;
} while (deletedCount == limit && iterations < MAX_ITERATIONS);
} while (deletedCount > 0 && iterations <= MAX_ITERATIONS);

return totalDeletedCount;
}

private int getLimit() {
int limit = defaultApplicationConfig.getConfigAsInt(CLEAR_LIMIT_KEY, DEFAULT_LIMIT);
if (limit == 0) {
return DEFAULT_LIMIT;
if (limit <= MIN_LIMIT) {
limit = DEFAULT_LIMIT;
} else if (limit > MAX_LIMIT) {
limit = MAX_LIMIT;
}
return limit;
}
Expand Down

0 comments on commit e662080

Please sign in to comment.