1
0
Fork 0

slow query keys are generated only when a query is slow instead for every query

This commit is contained in:
sspanak 2025-01-02 13:14:31 +02:00 committed by Dimo Karaivanov
parent 7c077fdb31
commit c80bb7ba42
2 changed files with 3 additions and 2 deletions

View file

@ -21,7 +21,7 @@ public class SlowQueryStats {
return language.getId() + "_" + sequence + "_" + wordFilter + "_" + minimumWords; return language.getId() + "_" + sequence + "_" + wordFilter + "_" + minimumWords;
} }
public static void add(String key, int time, String positionsList) { public static void add(Language language, String sequence, String wordFilter, int minimumWords, int time, String positionsList) {
if (firstQueryTime == -1) { if (firstQueryTime == -1) {
firstQueryTime = System.currentTimeMillis(); firstQueryTime = System.currentTimeMillis();
} }
@ -32,6 +32,7 @@ public class SlowQueryStats {
return; return;
} }
String key = generateKey(language, sequence, wordFilter, minimumWords);
slowQueries.put(key, time); slowQueries.put(key, time);
if (!resultCache.containsKey(key)) { if (!resultCache.containsKey(key)) {
resultCache.put(key, positionsList.replaceAll("-\\d+,", "")); resultCache.put(key, positionsList.replaceAll("-\\d+,", ""));

View file

@ -96,7 +96,7 @@ public class WordStore extends BaseSyncStore {
printLoadingSummary(sequence, words, longPositionsTime, positionsTime, wordsTime); printLoadingSummary(sequence, words, longPositionsTime, positionsTime, wordsTime);
if (!cancel.isCanceled()) { // do not cache empty results from aborted queries if (!cancel.isCanceled()) { // do not cache empty results from aborted queries
SlowQueryStats.add(SlowQueryStats.generateKey(language, sequence, wordFilter, minWords), (int) (positionsTime + wordsTime), positions); SlowQueryStats.add(language, sequence, wordFilter, minWords, (int) (positionsTime + wordsTime), positions);
} }
return words; return words;