From 9ed33778643868d5349f9f2d0e1c2fcbfae29891 Mon Sep 17 00:00:00 2001 From: Dmitry Zuikov Date: Wed, 12 Jun 2024 07:40:29 +0300 Subject: [PATCH] wip --- fixme-new/lib/Fixme/Run.hs | 20 +++++++++++++++----- fixme-new/lib/Fixme/State.hs | 7 +++++++ 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/fixme-new/lib/Fixme/Run.hs b/fixme-new/lib/Fixme/Run.hs index c626131a..35315bb3 100644 --- a/fixme-new/lib/Fixme/Run.hs +++ b/fixme-new/lib/Fixme/Run.hs @@ -567,11 +567,21 @@ runForms ss = for_ ss $ \s -> do warn $ red "IMPORT-FIXMIES" <+> pretty fn sto <- compactStorageOpen @HbSync mempty fn ks <- keys sto - 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 + + toImport <- S.toList_ do + for_ ks $ \k -> runMaybeT do + v <- get sto k & MaybeT + 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 diff --git a/fixme-new/lib/Fixme/State.hs b/fixme-new/lib/Fixme/State.hs index 564e117f..d6a02421 100644 --- a/fixme-new/lib/Fixme/State.hs +++ b/fixme-new/lib/Fixme/State.hs @@ -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