Commit 47aa6cf9 authored by Alfredo Di Napoli's avatar Alfredo Di Napoli

Better UniqParameter instance for Node and friends

parent 09d3152e
...@@ -72,7 +72,7 @@ import Gargantext.Database.Prelude ...@@ -72,7 +72,7 @@ import Gargantext.Database.Prelude
import Gargantext.Database.Schema.Node (NodePoly(..)) import Gargantext.Database.Schema.Node (NodePoly(..))
import Gargantext.Defaults qualified as Defaults import Gargantext.Defaults qualified as Defaults
import Gargantext.Prelude hiding (hash, toLower) import Gargantext.Prelude hiding (hash, toLower)
import Gargantext.Prelude.Crypto.Hash (hash) import Gargantext.Prelude.Crypto.Hash (hash, Hash)
{-| To Print result query {-| To Print result query
import Data.ByteString.Internal (ByteString) import Data.ByteString.Internal (ByteString)
...@@ -221,9 +221,9 @@ instance UniqParameters HyperdataContact ...@@ -221,9 +221,9 @@ instance UniqParameters HyperdataContact
where where
uniqParameters _ = "" uniqParameters _ = ""
instance UniqParameters (Node a) instance UniqParameters a => UniqParameters (Node a)
where where
uniqParameters _ = undefined uniqParameters = uniqParameters . _node_hyperdata
filterText :: Text -> Text filterText :: Text -> Text
...@@ -232,9 +232,13 @@ filterText = DT.toLower . DT.filter isAlphaNum ...@@ -232,9 +232,13 @@ filterText = DT.toLower . DT.filter isAlphaNum
instance (UniqParameters a, ToJSON a, HasDBid NodeType) => AddUniqId (Node a) instance (UniqParameters a, ToJSON a, HasDBid NodeType) => AddUniqId (Node a)
where where
addUniqId (Node nid _ t u p n d h) = Node nid (Just newHash) t u p n d h addUniqId node = node { _node_hash_id = Just $ newUniqIdHash node }
where where
newHash = "\\x" <> hash (uniqParameters h)
-- | Returns a new unique ID computed by hashing the uniq parameters of the input
-- and prefixing everything with '\\x'.
newUniqIdHash :: UniqParameters a => a -> Hash
newUniqIdHash a = "\\x" <> hash (uniqParameters a)
--------------------------------------------------------------------------- ---------------------------------------------------------------------------
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment