@@ -274,7 +274,7 @@ instance Store IndexRecord where
274
274
dataBlock <- peek
275
275
return $ IndexRecord idxBlock dataBlock
276
276
277
- lookupFileB :: B. ByteString -> Storage (Maybe ( M. Map DepthParams CacheItem ) )
277
+ lookupFileB :: B. ByteString -> Storage (Maybe PerBoardData )
278
278
lookupFileB bstr = do
279
279
st <- get
280
280
case ssData st of
@@ -311,14 +311,19 @@ lookupFile board depth side = Metrics.timed "cache.lookup.file" $ do
311
311
mbItem <- lookupFileB (encodeBoard board)
312
312
case mbItem of
313
313
Nothing -> return Nothing
314
- Just item -> case M. lookup depth item of
314
+ Just item -> case M. lookup depth (boardScores item) of
315
315
Nothing -> return Nothing
316
316
Just ci -> case side of
317
317
First -> return $ ciFirst ci
318
318
Second -> return $ ciSecond ci
319
319
320
- putRecordFileB :: B. ByteString -> DepthParams -> Side -> StorageValue -> Storage ()
321
- putRecordFileB bstr depth side value = do
320
+ lookupStatsFile :: Board -> Storage (Maybe Stats )
321
+ lookupStatsFile board = Metrics. timed " stats.lookup.file" $ do
322
+ mbItem <- lookupFileB (encodeBoard board)
323
+ return $ join $ boardStats `fmap` mbItem
324
+
325
+ putRecordFileB :: B. ByteString -> PerBoardData -> Storage ()
326
+ putRecordFileB bstr newData = do
322
327
st <- get
323
328
case ssData st of
324
329
Nothing -> return ()
@@ -338,17 +343,16 @@ putRecordFileB bstr depth side value = do
338
343
seek IndexFile idxOffset
339
344
writeData IndexFile record'
340
345
seek DataFile $ calcDataBlockOffset newDataBlock
341
- let newData = M. singleton depth newItem
342
346
writeDataSized DataFile newData
343
347
return ()
344
348
else do
345
- let dataOffset = calcDataBlockOffset dataBlockNumber
346
- seek DataFile dataOffset
347
- oldData <- readDataSized DataFile
348
- let newData = updateData oldData
349
- seek DataFile dataOffset
350
- writeDataSized DataFile newData
351
- return ()
349
+ let dataOffset = calcDataBlockOffset dataBlockNumber
350
+ seek DataFile dataOffset
351
+ oldData <- readDataSized DataFile
352
+ let newData' = oldData <> newData
353
+ seek DataFile dataOffset
354
+ writeDataSized DataFile newData'
355
+ return ()
352
356
| otherwise = do
353
357
bsize <- gets ssBoardSize
354
358
let idxOffset = calcIndexOffset bsize blockNumber (B. head bstr)
@@ -389,22 +393,14 @@ putRecordFileB bstr depth side value = do
389
393
writeBytes DataFile empty
390
394
return newBlockNumber
391
395
392
- updateData oldMap =
393
- M. insertWith updateItem depth newItem oldMap
394
-
395
- newItem = case side of
396
- First -> CacheItem {ciFirst = Just value, ciSecond = Nothing }
397
- Second -> CacheItem {ciFirst = Nothing , ciSecond = Just value}
398
-
399
- updateItem item1 item2 =
400
- case side of
401
- First -> item1 {ciFirst = ciFirst item2 `mplus` ciFirst item1}
402
- Second -> item2 {ciSecond = ciSecond item2 `mplus` ciSecond item1}
403
-
404
396
putRecordFile :: Board -> DepthParams -> Side -> StorageValue -> Storage ()
405
397
putRecordFile board depth side value = Metrics. timed " cache.put.file" $ do
406
398
let bstr = encodeBoard board
407
- putRecordFileB bstr depth side value
399
+ newData = PerBoardData (M. singleton depth item) Nothing
400
+ item = case side of
401
+ First -> CacheItem {ciFirst = Just value, ciSecond = Nothing }
402
+ Second -> CacheItem {ciFirst = Nothing , ciSecond = Just value}
403
+ putRecordFileB bstr newData
408
404
409
405
initFile :: Storage ()
410
406
initFile = do
0 commit comments