From 278adbb726cf95660d2acec6ff28f8f43b196a51 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Wed, 28 Aug 2024 11:00:59 -0400 Subject: [PATCH] combine 2 queries --- Database/RepoSize.hs | 23 +++++++++++------------ doc/todo/git-annex_proxies.mdwn | 8 ++------ 2 files changed, 13 insertions(+), 18 deletions(-) diff --git a/Database/RepoSize.hs b/Database/RepoSize.hs index c1f1e98d51..1ea8c702a2 100644 --- a/Database/RepoSize.hs +++ b/Database/RepoSize.hs @@ -247,19 +247,18 @@ removeLiveSizeChange u k sc sid = , LiveSizeChangesChange ==. sc ] -getLiveSizeChanges :: SqlPersistM (M.Map UUID [(Key, (SizeChange, SizeChangeId))]) -getLiveSizeChanges = M.fromListWith (++) . map conv <$> selectList [] [] +getLiveSizeChangesMap :: SqlPersistM (M.Map UUID [(Key, (SizeChange, SizeChangeId))]) +getLiveSizeChangesMap = M.fromListWith (++) . map conv <$> getLiveSizeChanges where - conv entity = - let LiveSizeChanges u k sid sc = entityVal entity - in (u, [(k, (sc, sid))]) + conv (LiveSizeChanges u k sid sc) = (u, [(k, (sc, sid))]) -getLiveSizeChanges' :: SqlPersistM [(UUID, Key, SizeChange)] -getLiveSizeChanges' = map conv <$> selectList [] [] +getLiveSizeChangesList :: SqlPersistM [(UUID, Key, SizeChange)] +getLiveSizeChangesList = map conv <$> getLiveSizeChanges where - conv entity = - let LiveSizeChanges u k _sid sc = entityVal entity - in (u, k, sc) + conv (LiveSizeChanges u k _sid sc) = (u, k, sc) + +getLiveSizeChanges :: SqlPersistM [LiveSizeChanges] +getLiveSizeChanges = map entityVal <$> selectList [] [] getSizeChanges :: SqlPersistM (M.Map UUID FileSize) getSizeChanges = M.fromList . map conv <$> selectList [] [] @@ -310,7 +309,7 @@ getRecentChanges = map conv <$> selectList [] [] - redundant with a recent change. -} clearRecentChanges :: SqlPersistM () clearRecentChanges = do - live <- getLiveSizeChanges' + live <- getLiveSizeChangesList if null live then deleteWhere ([] :: [Filter RecentChanges]) else do @@ -354,7 +353,7 @@ recordedRepoOffsets (RepoSizeHandle Nothing) = pure mempty liveRepoOffsets :: RepoSizeHandle -> IO (M.Map UUID SizeOffset) liveRepoOffsets (RepoSizeHandle (Just h)) = H.queryDb h $ do sizechanges <- getSizeChanges - livechanges <- getLiveSizeChanges + livechanges <- getLiveSizeChangesMap let us = S.toList $ S.fromList $ M.keys sizechanges ++ M.keys livechanges M.fromList <$> forM us (go sizechanges livechanges) diff --git a/doc/todo/git-annex_proxies.mdwn b/doc/todo/git-annex_proxies.mdwn index 7621f4f878..5db949cec6 100644 --- a/doc/todo/git-annex_proxies.mdwn +++ b/doc/todo/git-annex_proxies.mdwn @@ -58,18 +58,14 @@ Planned schedule of work: used. annex.pidlock might otherwise prevent running more than one git-annex at a time. - , or alternatively - when checking a preferred content expression that uses balanced preferred - content. - * The assistant is using NoLiveUpdate, but it should be posssible to plumb a LiveUpdate through it from preferred content checking to location log updating. * `git-annex info` in the limitedcalc path in cachedAllRepoData double-counts redundant information from the journal due to using - overLocationLogs. In the other path it does not, and this should be fixed - for consistency and correctness. + overLocationLogs. In the other path it does not (any more; it used to), + and this should be fixed for consistency and correctness. * getLiveRepoSizes has a filterM getRecentChange over the live updates. This could be optimised to a single sql join. There are usually not many