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
sto <- compactStorageOpen @HbSync mempty fn
ks <- keys sto
toImport <- S.toList_ do
for_ ks $ \k -> runMaybeT do
v <- get sto k & MaybeT
warn $ red "import" <+> viaShow (toBase58 k)
fx <- deserialiseOrFail @Fixme (LBS.fromStrict v) & toMPlus
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

View File

@ -25,6 +25,7 @@ module Fixme.State
, insertProcessed
, isProcessed
, selectProcessed
, checkFixmeExists
, HasPredicate(..)
, SelectPredicate(..)
) where
@ -43,6 +44,7 @@ import Data.HashMap.Strict qualified as HM
import Text.InterpolatedString.Perl6 (q,qc)
import Data.Text qualified as Text
import Data.Maybe
import Data.List qualified as List
import Data.Either
import Data.List (sortBy,sortOn)
import Data.Ord
@ -439,6 +441,11 @@ selectFixme txt = do
<&> 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
instance ToField Bound where