This commit is contained in:
Dmitry Zuikov 2024-06-12 07:40:29 +03:00
parent 49acdbe5f4
commit 9ed3377864
2 changed files with 22 additions and 5 deletions

View File

@ -567,11 +567,21 @@ runForms ss = for_ ss $ \s -> do
warn $ red "IMPORT-FIXMIES" <+> pretty fn warn $ red "IMPORT-FIXMIES" <+> pretty fn
sto <- compactStorageOpen @HbSync mempty fn sto <- compactStorageOpen @HbSync mempty fn
ks <- keys sto ks <- keys sto
for_ ks $ \k -> runMaybeT do
v <- get sto k & MaybeT toImport <- S.toList_ do
warn $ red "import" <+> viaShow (toBase58 k) for_ ks $ \k -> runMaybeT do
fx <- deserialiseOrFail @Fixme (LBS.fromStrict v) & toMPlus v <- get sto k & MaybeT
lift $ withState $ insertFixme fx Added _ fx <- deserialiseOrFail @CompactAction (LBS.fromStrict v) & toMPlus
let ha = hashObject @HbSync (serialise fx)
here <- lift $ lift $ checkFixmeExists (HashRef ha)
unless here do
warn $ red "import" <+> viaShow (pretty ha)
lift $ S.yield fx
withState $ transactional do
for_ toImport insertFixme
updateIndexes
compactStorageClose sto compactStorageClose sto

View File

@ -25,6 +25,7 @@ module Fixme.State
, insertProcessed , insertProcessed
, isProcessed , isProcessed
, selectProcessed , selectProcessed
, checkFixmeExists
, HasPredicate(..) , HasPredicate(..)
, SelectPredicate(..) , SelectPredicate(..)
) where ) where
@ -43,6 +44,7 @@ import Data.HashMap.Strict qualified as HM
import Text.InterpolatedString.Perl6 (q,qc) import Text.InterpolatedString.Perl6 (q,qc)
import Data.Text qualified as Text import Data.Text qualified as Text
import Data.Maybe import Data.Maybe
import Data.List qualified as List
import Data.Either import Data.Either
import Data.List (sortBy,sortOn) import Data.List (sortBy,sortOn)
import Data.Ord import Data.Ord
@ -439,6 +441,11 @@ selectFixme txt = do
<&> over (field @"fixmeAttr") (<> attrs) <&> over (field @"fixmeAttr") (<> attrs)
checkFixmeExists :: FixmePerks m => HashRef -> FixmeM m Bool
checkFixmeExists what = withState do
select @(Only (Maybe Int)) [qc|select 1 from fixme where id = ? limit 1|] (Only what)
<&> not . List.null
data Bound = forall a . (ToField a, Show a) => Bound a data Bound = forall a . (ToField a, Show a) => Bound a
instance ToField Bound where instance ToField Bound where