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
import Gargantext.Database.Schema.Node (NodePoly(..))
import Gargantext.Defaults qualified as Defaults
import Gargantext.Prelude hiding (hash, toLower)
import Gargantext.Prelude.Crypto.Hash (hash)
import Gargantext.Prelude.Crypto.Hash (hash, Hash)
{-| To Print result query
import Data.ByteString.Internal (ByteString)
......@@ -221,9 +221,9 @@ instance UniqParameters HyperdataContact
where
uniqParameters _ = ""
instance UniqParameters (Node a)
instance UniqParameters a => UniqParameters (Node a)
where
uniqParameters _ = undefined
uniqParameters = uniqParameters . _node_hyperdata
filterText :: Text -> Text
......@@ -232,9 +232,13 @@ filterText = DT.toLower . DT.filter isAlphaNum
instance (UniqParameters a, ToJSON a, HasDBid NodeType) => AddUniqId (Node a)
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
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