@@ -8,6 +8,7 @@ module Share.Web.UCM.HistoryComments.Queries
88where
99
1010import Control.Lens
11+ import Data.Foldable qualified as Foldable
1112import Data.Set qualified as Set
1213import Data.Set.NonEmpty (NESet )
1314import Data.Set.NonEmpty qualified as NESet
@@ -71,9 +72,12 @@ insertThumbprints :: (PG.QueryA m) => NESet Text -> m ()
7172insertThumbprints thumbprints = do
7273 PG. execute_
7374 [PG. sql |
75+ WITH thumbprints(thumbprint) AS (
76+ SELECT * FROM ^{PG.singleColumnTable $ Foldable.toList thumbprints}
77+ )
7478 INSERT INTO personal_keys (thumbprint)
75- SELECT * FROM ^{PG.singleColumnTable $ toList thumbprints}
76- ON CONFLICT (thumbprint) DO NOTHING
79+ SELECT thumbprint FROM thumbprints
80+ ON CONFLICT DO NOTHING
7781 |]
7882
7983-- Convert milliseconds since epoch to UTCTime _exactly_.
@@ -111,18 +115,19 @@ insertHistoryComments !_authZ projectId chunks = PG.pipelined $ do
111115 PG. execute_
112116 [PG. sql |
113117 WITH new_comments(author, created_at_ms, author_thumbprint, causal_hash, comment_hash) AS (
114- VALUES ^{PG.toTable commentsTable}
118+ SELECT * FROM ^{PG.toTable commentsTable}
115119 )
116120 INSERT INTO history_comments(causal_id, author, created_at_ms, comment_hash, author_key_id)
117121 SELECT causal.id, nc.author, nc.created_at_ms, nc.comment_hash, pk.id
118122 FROM new_comments nc
119- JOIN causal causal
123+ JOIN causals causal
120124 ON causal.hash = nc.causal_hash
121125 JOIN personal_keys pk
122126 ON pk.thumbprint = nc.author_thumbprint
123- ON CONFLICT DO NOTHING
127+ ON CONFLICT (comment_hash) DO NOTHING
124128 |]
125129 where
130+ commentsTable :: [(Text , Int64 , Text , Hash32 , Hash32 )]
126131 commentsTable =
127132 comments <&> \ HistoryComment {.. } ->
128133 ( author,
0 commit comments