Added caching strategy when (deep) comparing decks

Deck model comparison may be triggered a certain number of times, and the new deep-comparison on each part may slow down performance in deck editor. Therefore, a caching strategy has been integrated to avoid comparing the same objects multiple times.
This commit is contained in:
leriomaggio
2021-10-29 10:36:34 +01:00
parent 663ebd4120
commit 237a423180

View File

@@ -241,10 +241,14 @@ public class DeckController<T extends DeckBase> {
} }
} }
private Boolean isInSyncCacheResult = null;
private T syncModelCache = null;
private boolean isModelInSyncWithFolder() { private boolean isModelInSyncWithFolder() {
if (model.getName().isEmpty()) { if (syncModelCache != null && model == syncModelCache)
return isInSyncCacheResult;
if (model.getName().isEmpty())
return true; return true;
}
final T modelStored = currentFolder.get(model.getName()); final T modelStored = currentFolder.get(model.getName());
// checks presence in dictionary only. // checks presence in dictionary only.
@@ -254,8 +258,9 @@ public class DeckController<T extends DeckBase> {
if (modelStored == null) { if (modelStored == null) {
return false; return false;
} }
syncModelCache = model;
return modelStored.equals(model); isInSyncCacheResult = modelStored.equals(model);
return isInSyncCacheResult;
} }
/** /**