Skip to content

Commit d6ba241

Browse files
committed
Don't use ByteString in Cache
1 parent 106f6a5 commit d6ba241

File tree

2 files changed

+8
-20
lines changed

2 files changed

+8
-20
lines changed

cardano-db-sync/src/Cardano/DbSync/Cache.hs

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -159,31 +159,19 @@ queryStakeAddrWithCacheRetBs ::
159159
Network ->
160160
StakeCred ->
161161
ReaderT SqlBackend m (Either (DB.LookupFail, ByteString) DB.StakeAddressId)
162-
queryStakeAddrWithCacheRetBs trce cache cacheUA nw cred = do
163-
let !bs = Ledger.serialiseRewardAccount (Ledger.RewardAccount nw cred)
162+
queryStakeAddrWithCacheRetBs _trce cache cacheUA nw cred = do
163+
let bs = Ledger.serialiseRewardAccount (Ledger.RewardAccount nw cred)
164164
case cache of
165165
NoCache -> do
166166
mapLeft (,bs) <$> resolveStakeAddress bs
167167
ActiveCache ci -> do
168-
prevCache <- liftIO $ readTVarIO (cStakeRawHashes ci)
169-
let isNewCache = LRU.getSize prevCache < 1
170-
-- populate from db if the cache is empty
171-
currentCache <-
172-
if isNewCache
173-
then do
174-
liftIO $ logInfo trce "Stake Raw Hashes cache is new and empty. Populating with addresses from db..."
175-
queryRes <- DB.queryAddressWithReward (fromIntegral $ LRU.getCapacity prevCache)
176-
liftIO $ atomically $ writeTVar (cStakeRawHashes ci) $ LRU.fromList queryRes prevCache
177-
liftIO $ logInfo trce "Population of cache complete."
178-
liftIO $ readTVarIO (cStakeRawHashes ci)
179-
else pure prevCache
180-
181-
case LRU.lookup bs currentCache of
168+
currentCache <- liftIO $ readTVarIO (cStakeRawHashes ci)
169+
case LRU.lookup cred currentCache of
182170
Just (addrId, lruCache) -> do
183171
liftIO $ hitCreds (cStats ci)
184172
case cacheUA of
185173
EvictAndUpdateCache -> do
186-
liftIO $ atomically $ writeTVar (cStakeRawHashes ci) $ LRU.delete bs lruCache
174+
liftIO $ atomically $ writeTVar (cStakeRawHashes ci) $ LRU.delete cred lruCache
187175
pure $ Right addrId
188176
_other -> do
189177
liftIO $ atomically $ writeTVar (cStakeRawHashes ci) lruCache
@@ -198,7 +186,7 @@ queryStakeAddrWithCacheRetBs trce cache cacheUA nw cred = do
198186
liftIO $
199187
atomically $
200188
modifyTVar (cStakeRawHashes ci) $
201-
LRU.insert bs stakeAddrsId
189+
LRU.insert cred stakeAddrsId
202190
pure $ Right stakeAddrsId
203191

204192
queryPoolKeyWithCache ::

cardano-db-sync/src/Cardano/DbSync/Cache/Types.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import Cardano.DbSync.Cache.FIFO (FIFOCache)
3333
import qualified Cardano.DbSync.Cache.FIFO as FIFO
3434
import Cardano.DbSync.Cache.LRU (LRUCache)
3535
import qualified Cardano.DbSync.Cache.LRU as LRU
36-
import Cardano.DbSync.Types (DataHash, PoolKeyHash)
36+
import Cardano.DbSync.Types (DataHash, PoolKeyHash, StakeCred)
3737
import Cardano.Ledger.Mary.Value (AssetName, PolicyID)
3838
import qualified Cardano.Ledger.TxIn as Ledger
3939
import Cardano.Prelude
@@ -62,7 +62,7 @@ data CacheAction
6262
deriving (Eq)
6363

6464
data CacheInternal = CacheInternal
65-
{ cStakeRawHashes :: !(StrictTVar IO (LRUCache ByteString DB.StakeAddressId))
65+
{ cStakeRawHashes :: !(StrictTVar IO (LRUCache StakeCred DB.StakeAddressId))
6666
, cPools :: !(StrictTVar IO StakePoolCache)
6767
, cDatum :: !(StrictTVar IO (LRUCache DataHash DB.DatumId))
6868
, cMultiAssets :: !(StrictTVar IO (LRUCache (PolicyID StandardCrypto, AssetName) DB.MultiAssetId))

0 commit comments

Comments
 (0)