@@ -33,7 +33,7 @@ import qualified Cardano.Db as DB
33
33
import Cardano.DbSync.Cache.Epoch (rollbackMapEpochInCache )
34
34
import qualified Cardano.DbSync.Cache.FIFO as FIFO
35
35
import qualified Cardano.DbSync.Cache.LRU as LRU
36
- import Cardano.DbSync.Cache.Types (CacheAction (.. ), CacheInternal (.. ), CacheStatistics (.. ), CacheStatus (.. ), StakeCache (.. ), initCacheStatistics )
36
+ import Cardano.DbSync.Cache.Types (CacheAction (.. ), CacheInternal (.. ), CacheStatistics (.. ), CacheStatus (.. ), StakeCache (.. ), initCacheStatistics , shouldCache )
37
37
import qualified Cardano.DbSync.Era.Shelley.Generic.Util as Generic
38
38
import Cardano.DbSync.Era.Shelley.Query
39
39
import Cardano.DbSync.Era.Util
@@ -94,7 +94,7 @@ queryOrInsertRewardAccount ::
94
94
Ledger. RewardAccount StandardCrypto ->
95
95
ReaderT SqlBackend m DB. StakeAddressId
96
96
queryOrInsertRewardAccount trce cache cacheUA rewardAddr = do
97
- eiAddrId <- queryRewardAccountWithCacheRetBs trce cache cacheUA rewardAddr
97
+ eiAddrId <- queryStakeAddrWithCacheRetBs trce cache cacheUA rewardAddr
98
98
case eiAddrId of
99
99
Left (_err, bs) -> insertStakeAddress rewardAddr (Just bs)
100
100
Right addrId -> pure addrId
@@ -127,17 +127,6 @@ insertStakeAddress rewardAddr stakeCredBs = do
127
127
where
128
128
addrBs = fromMaybe (Ledger. serialiseRewardAccount rewardAddr) stakeCredBs
129
129
130
- queryRewardAccountWithCacheRetBs ::
131
- forall m .
132
- MonadIO m =>
133
- Trace IO Text ->
134
- CacheStatus ->
135
- CacheAction ->
136
- Ledger. RewardAccount StandardCrypto ->
137
- ReaderT SqlBackend m (Either (DB. LookupFail , ByteString ) DB. StakeAddressId )
138
- queryRewardAccountWithCacheRetBs trce cache cacheUA rwdAcc =
139
- queryStakeAddrWithCacheRetBs trce cache cacheUA (Ledger. raNetwork rwdAcc) (Ledger. raCredential rwdAcc)
140
-
141
130
queryStakeAddrWithCache ::
142
131
forall m .
143
132
MonadIO m =>
@@ -148,26 +137,25 @@ queryStakeAddrWithCache ::
148
137
StakeCred ->
149
138
ReaderT SqlBackend m (Either DB. LookupFail DB. StakeAddressId )
150
139
queryStakeAddrWithCache trce cache cacheUA nw cred =
151
- mapLeft fst <$> queryStakeAddrWithCacheRetBs trce cache cacheUA nw cred
140
+ mapLeft fst <$> queryStakeAddrWithCacheRetBs trce cache cacheUA ( Ledger. RewardAccount nw cred)
152
141
153
142
queryStakeAddrWithCacheRetBs ::
154
143
forall m .
155
144
MonadIO m =>
156
145
Trace IO Text ->
157
146
CacheStatus ->
158
147
CacheAction ->
159
- Network ->
160
- StakeCred ->
148
+ Ledger. RewardAccount StandardCrypto ->
161
149
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)
150
+ queryStakeAddrWithCacheRetBs _trce cache cacheUA ra @ ( Ledger. RewardAccount _ cred) = do
151
+ let bs = Ledger. serialiseRewardAccount ra
164
152
case cache of
165
153
NoCache -> do
166
154
mapLeft (,bs) <$> resolveStakeAddress bs
167
155
ActiveCache ci -> do
168
156
stakeCache <- liftIO $ readTVarIO (cStake ci)
169
157
case queryStakeCache cred stakeCache of
170
- Just (addrId, stakeCache', _ ) -> do
158
+ Just (addrId, stakeCache') -> do
171
159
liftIO $ hitCreds (cStats ci)
172
160
case cacheUA of
173
161
EvictAndUpdateCache -> do
@@ -192,11 +180,11 @@ queryStakeAddrWithCacheRetBs _trce cache cacheUA nw cred = do
192
180
pure $ Right stakeAddrsId
193
181
194
182
-- | True if it was found in LRU
195
- queryStakeCache :: StakeCred -> StakeCache -> Maybe (DB. StakeAddressId , StakeCache , Bool )
183
+ queryStakeCache :: StakeCred -> StakeCache -> Maybe (DB. StakeAddressId , StakeCache )
196
184
queryStakeCache scred scache = case Map. lookup scred (scStableCache scache) of
197
- Just addrId -> Just (addrId, scache, False )
185
+ Just addrId -> Just (addrId, scache)
198
186
Nothing -> case LRU. lookup scred (scLruCache scache) of
199
- Just (addrId, lru') -> Just (addrId, scache {scLruCache = lru'}, True )
187
+ Just (addrId, lru') -> Just (addrId, scache {scLruCache = lru'})
200
188
Nothing -> Nothing
201
189
202
190
deleteStakeCache :: StakeCred -> StakeCache -> StakeCache
@@ -235,7 +223,7 @@ queryPoolKeyWithCache cache cacheUA hsh =
235
223
Nothing -> pure $ Left (DB. DbLookupMessage " PoolKeyHash" )
236
224
Just phId -> do
237
225
-- missed so we can't evict even with 'EvictAndReturn'
238
- when (cacheUA == UpdateCache ) $
226
+ when (shouldCache cacheUA ) $
239
227
liftIO $
240
228
atomically $
241
229
modifyTVar (cPools ci) $
@@ -275,7 +263,7 @@ insertPoolKeyWithCache cache cacheUA pHash =
275
263
{ DB. poolHashHashRaw = Generic. unKeyHashRaw pHash
276
264
, DB. poolHashView = Generic. unKeyHashView pHash
277
265
}
278
- when (cacheUA == UpdateCache ) $
266
+ when (shouldCache cacheUA ) $
279
267
liftIO $
280
268
atomically $
281
269
modifyTVar (cPools ci) $
0 commit comments