powsybl / powsybl-network-store

Persistent implementation of PowSyBl network based on Spring Boot
Mozilla Public License 2.0
3 stars 6 forks source link

cleanup PreloadingNetworkStoreClient assumes its delegate is CachedNetworkStoreClient #420

Open jonenst opened 4 months ago

jonenst commented 4 months ago

Describe the current behavior

public List<Resource<SubstationAttributes>> getSubstations(UUID networkUuid, int variantNum) {
    ensureCached(ResourceType.SUBSTATION, networkUuid, variantNum);
    return delegate.getSubstations(networkUuid, variantNum);
}

private void ensureCached(ResourceType resourceType, UUID networkUuid, int variantNum) {
    loadToCache(resourceType, networkUuid, variantNum);
    resourceTypes.add(resourceType);
} 

private void loadToCache(ResourceType resourceType, UUID networkUuid, int variantNum) {
    delegate.getSubstations(networkUuid, variantNum);
}

wee call getSubstations twice, so it works only for CachedNetworkStoreClient

Describe the expected behavior

refactor the code to force the delegate to be of type cachednetworkstoreclient for preloadingnetworkstoreclient ? because it doesn't make sense to preload for a client that doesn't not cache.

Describe the motivation

reduce code complexity

Extra Information

No response

jonenst commented 4 months ago

when we are not preloading, we should call the delegate only once (e.g. getSubstations() and not ALL_COLLECTION_FOR_BUS_VIEW or getSwitches) when we are preloading (first time calling (checked with cachedResourcesTypes) either getSubstation() or getSubstations and ALL_COLLECTION_FOR_BUS_VIEW), call the method with more data, and then call the right method.