Skip to content

Commit d0bcef5

Browse files
committed
Refactor as suggested in review comments
Signed-off-by: Kristiyan Selveliev <[email protected]>
1 parent 7ec3a14 commit d0bcef5

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

web3/src/main/java/org/hiero/mirror/web3/service/ContractStateServiceImpl.java

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -85,18 +85,22 @@ public Optional<byte[]> findStorageByBlockTimestamp(
8585
private Optional<byte[]> findStorageBatch(final EntityId contractId, final byte[] key) {
8686
final var contractSlotsCache = ((CaffeineCache) this.contractSlotsCache.get(
8787
contractId, () -> cacheManagerSlotsPerContract.getCache(contractId.toString())));
88+
final var wrappedKey = ByteBuffer.wrap(key);
8889
// Cached slot keys for contract, whose slot values are not present in the contractStateCache
89-
contractSlotsCache.putIfAbsent(ByteBuffer.wrap(key), EMPTY_VALUE);
90-
final var cachedSlots = contractSlotsCache.getNativeCache().asMap().keySet();
91-
92-
final var contractSlotValues = contractStateRepository.findStorageBatch(
93-
contractId.getId(),
94-
cachedSlots.stream()
95-
.map(slot -> ((ByteBuffer) slot).array())
96-
.toList()
97-
);
98-
boolean isKeyEvictedFromCache =
99-
!cachedSlots.contains(ByteBuffer.wrap(key).array());
90+
contractSlotsCache.putIfAbsent(wrappedKey, EMPTY_VALUE);
91+
final var cachedSlotKeys = contractSlotsCache.getNativeCache().asMap().keySet();
92+
93+
final var cachedSlots = new ArrayList<byte[]>(cachedSlotKeys.size());
94+
boolean isKeyEvictedFromCache = true;
95+
96+
for (var slot : cachedSlotKeys) {
97+
cachedSlots.add(((ByteBuffer) slot).array());
98+
if (wrappedKey.equals(slot)) {
99+
isKeyEvictedFromCache = false;
100+
}
101+
}
102+
103+
final var contractSlotValues = contractStateRepository.findStorageBatch(contractId.getId(), cachedSlots);
100104
byte[] cachedValue = null;
101105

102106
for (final var contractSlotValue : contractSlotValues) {

0 commit comments

Comments
 (0)