Skip to content

Commit

Permalink
Merge pull request #23 from unisoncomputing/cp/fix-hasql-exception-ha…
Browse files Browse the repository at this point in the history
…ndling

Use custom fork of hasql-pool for better exception handling for Postgres Connections
  • Loading branch information
ChrisPenner authored Sep 3, 2024
2 parents a16bd39 + b5da5ff commit 686adcc
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 9 deletions.
17 changes: 13 additions & 4 deletions src/Share/Postgres/Search/DefinitionSearch/Queries.hs
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,9 @@ defNameCompletionSearch mayCaller mayFilter (Query query) limit = do
-- then matches where the query is near the end of the name,
-- e.g. for query 'List', 'data.List' should come before 'data.List.map'
ORDER BY r.tag <> 'doc'::definition_tag DESC, r.tag <> 'test'::definition_tag DESC,
r.name LIKE ('%' || #{query} || '%') DESC, length(r.name) - position(LOWER(#{query}) in LOWER(r.name)) ASC
r.name LIKE ('%' || #{query} || '%') DESC, length(r.name) - position(LOWER(#{query}) in LOWER(r.name)) ASC,
-- tie break by name, this just helps keep things deterministic for tests
r.name
LIMIT #{limit}

|]
Expand Down Expand Up @@ -329,7 +331,9 @@ definitionTokenSearch mayCaller mayFilter limit searchTokens preferredArity = do
(#{mayReturnTokensText} IS NOT NULL AND (tsquery(#{mayReturnTokensText}) @@ doc.search_tokens)) DESC,
EXISTS (SELECT FROM project_categories pc WHERE pc.project_id = doc.project_id) DESC,
doc.arity ASC,
length(doc.search_tokens) ASC
length(doc.search_tokens) ASC,
-- tie break by name, this just helps keep things deterministic for tests
doc.name
|]
Just (name, _) ->
-- Scoring for if there is a name search
Expand All @@ -340,7 +344,9 @@ definitionTokenSearch mayCaller mayFilter limit searchTokens preferredArity = do
length(doc.name) - position(LOWER(#{name}) in LOWER(doc.name)) ASC,
EXISTS (SELECT FROM project_categories pc WHERE pc.project_id = doc.project_id) DESC,
doc.arity ASC,
length(doc.search_tokens) ASC
length(doc.search_tokens) ASC,
-- tie break by name, this just helps keep things deterministic for tests
doc.name
|]
rows <-
queryListRows @(ProjectId, ReleaseId, Name, Hasql.Jsonb)
Expand Down Expand Up @@ -398,7 +404,10 @@ definitionNameSearch mayCaller mayFilter limit (Query query) = do
ORDER BY EXISTS (SELECT FROM project_categories pc WHERE pc.project_id = doc.project_id) DESC,
doc.name LIKE ('%' || #{query} || '%') DESC,
length(doc.name) - position(LOWER(#{query}) in LOWER(doc.name)) ASC,
word_similarity(#{query}, doc.name) DESC
word_similarity(#{query}, doc.name) DESC,
-- Tiebreak by name, this just helps keep things deterministic for tests and
-- such.
doc.name
LIMIT #{limit}
|]
rows
Expand Down
9 changes: 8 additions & 1 deletion stack.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,14 @@ extra-deps:

# Bumping hasql up to get Pipelining mode
- hasql-1.8
- hasql-pool-1.2.0.2
# Forked version of hasql-pool which doesn't return
# connections to the pool when an exception occurs.
# This is the `reset-connections-on-exception` branch.
#
# See: https://github.com/nikita-volkov/hasql-pool/issues/46
# Previously: - hasql-pool-1.2.0.2
- github: ChrisPenner/hasql-pool
commit: 3910e71505c80f944c201e2b981e9830494e1dbb
- hasql-interpolate-1.0.1.0
- postgresql-binary-0.14@sha256:3f3518f841cf80b107862800715bc64f43c2c71696c4129f63404c1ff61cc919,4025
- postgresql-libpq-0.10.1.0@sha256:6a45edff0a9e30b32cda6e443107950492322622c4fbefc8fb4dcf6452dcf0b4,3203
Expand Down
12 changes: 8 additions & 4 deletions stack.yaml.lock
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,16 @@ packages:
original:
hackage: hasql-1.8
- completed:
hackage: hasql-pool-1.2.0.2@sha256:621e3997d701b424a777fc6cd0218e385c89dff9417a933305d19b03820deb3f,2389
name: hasql-pool
pantry-tree:
sha256: 8dd1ee8e3a41894266708e28076a902c8d51b275af22c3f182d6bfe219ea7fa7
size: 982
sha256: 3f2da91d2be6c2dfb082d0454ca0571dcb5e56ff76cef919f3800f62f26f0da6
size: 1518
sha256: 293b48e94da99a2fb218c136d026e84414a8994506f09b1021e503ed622a4390
size: 30457
url: https://github.com/ChrisPenner/hasql-pool/archive/3910e71505c80f944c201e2b981e9830494e1dbb.tar.gz
version: 1.2.0.2
original:
hackage: hasql-pool-1.2.0.2
url: https://github.com/ChrisPenner/hasql-pool/archive/3910e71505c80f944c201e2b981e9830494e1dbb.tar.gz
- completed:
hackage: hasql-interpolate-1.0.1.0@sha256:07980986467ed196e812a54c2762a42ceca56ca899cb4ef3cdb4f4191b07d338,3298
pantry-tree:
Expand Down

0 comments on commit 686adcc

Please sign in to comment.