Skip to content

Commit 03b7568

Browse files
authored
Merge pull request #1995 from input-output-hk/KtorZ/1867/pool-next-metadata-fetch
revised SQL query returning next pool metadata to fetch
2 parents d51b74d + 5c22399 commit 03b7568

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

lib/core/src/Cardano/Pool/DB/Sqlite.hs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -268,22 +268,32 @@ newDBLayer trace fp timeInterpreter = do
268268
let fetchAttempts = tableName (DBField PoolFetchAttemptsMetadataHash)
269269
let metadata = tableName (DBField PoolMetadataHash)
270270
let query = T.unwords
271-
[ "SELECT"
272-
, metadataUrl, ",", metadataHash
273-
, "FROM", registrations
271+
[ "SELECT", "a." <> metadataUrl, ",", "a." <> metadataHash
272+
, "FROM", registrations, "AS a"
273+
, "LEFT JOIN", fetchAttempts, "AS b"
274+
, "ON"
275+
, "a." <> metadataUrl, "=", "b." <> metadataUrl, "AND"
276+
, "a." <> metadataHash, "=", "b." <> metadataHash
274277
, "WHERE"
275-
, metadataHash, "NOT", "IN" -- Successfully fetched metadata
278+
-- Successfully fetched metadata
279+
, "a." <> metadataHash, "NOT", "IN"
276280
, "("
277281
, "SELECT", metadataHash
278282
, "FROM", metadata
279283
, ")"
280284
, "AND"
281-
, metadataHash, "NOT", "IN" -- Recently failed urls
285+
-- Discard recent failed attempts
282286
, "("
283-
, "SELECT", metadataHash
284-
, "FROM", fetchAttempts
285-
, "WHERE", retryAfter, ">=", "datetime('now')"
287+
, retryAfter, "<", "datetime('now')"
288+
, "OR"
289+
, retryAfter, "IS NULL"
286290
, ")"
291+
-- Important, since we have a limit, we order all results by
292+
-- earlist "retry_after", so that we are sure that all
293+
-- metadata gets _eventually_ processed.
294+
--
295+
-- Note that `NULL` is smaller than everything.
296+
, "ORDER BY", retryAfter, "ASC"
287297
, "LIMIT", nLimit
288298
, ";"
289299
]

lib/core/src/Cardano/Pool/Metadata.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ fetchFromRemote tr builders manager url hash = runExceptTLog $ do
169169

170170
getChunk :: URI -> ExceptT String IO (Maybe ByteString)
171171
getChunk uri = do
172-
req <- requestFromURI uri
172+
req <- withExceptT show $ except $ requestFromURI uri
173173
liftIO $ traceWith tr $ MsgFetchPoolMetadata hash uri
174174
ExceptT
175175
$ handle fromIOException

0 commit comments

Comments
 (0)