Skip to content

Commit 261fcd0

Browse files
authored
Merge pull request #173 from unisoncomputing/bump-lts
Bump lts resolver
2 parents 9a822b2 + f0503b9 commit 261fcd0

41 files changed

Lines changed: 278 additions & 208 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,6 @@ prelude.output.md
2323

2424
# Developers can customize their own local development setup
2525
/transcripts/fixtures/custom_projects.txt
26+
27+
# Debugging output
28+
share.out

share-api/src/Share.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ mkShareServer env = do
136136
pure waiApp
137137
where
138138
gzipSettings =
139-
Gzip.def
139+
Gzip.defaultGzipSettings
140140
{ Gzip.gzipFiles = Gzip.GzipCompress,
141141
Gzip.gzipCheckMime = \mime -> Gzip.defaultCheckMime mime || mime == "application/cbor"
142142
}

share-api/src/Share/Env.hs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@ import Data.Functor
1313
import Data.HashMap.Strict qualified as HM
1414
import Data.Map qualified as Map
1515
import Data.Set qualified as Set
16+
import Data.String qualified as String
1617
import Data.Text qualified as Text
1718
import Data.Text.Encoding qualified as Text
1819
import Data.Time.Clock qualified as Time
1920
import Database.Redis qualified as Redis
21+
import Hasql.Connection qualified as Hasql
2022
import Hasql.Pool qualified as Pool
2123
import Hasql.Pool.Config qualified as Pool
2224
import Network.HTTP.Client qualified as HTTPClient
@@ -52,7 +54,7 @@ withEnv action = do
5254
'0' : _ -> False
5355
[] -> False
5456
_ -> True
55-
postgresConfig <- fromEnv "SHARE_POSTGRES" (pure . Right . Text.pack)
57+
postgresConfig <- fromEnv "SHARE_POSTGRES" (pure . Right . String.fromString @Hasql.Settings)
5658
postgresConnMax <- fromEnv "SHARE_POSTGRES_CONN_MAX" (pure . maybeToEither "Invalid SHARE_POSTGRES_CONN_MAX" . readMaybe)
5759
githubClientID <- fromEnv "SHARE_GITHUB_CLIENTID" (pure . Right . Text.pack)
5860
githubClientSecret <- fromEnv "SHARE_GITHUB_CLIENT_SECRET" (pure . Right . Text.pack)
@@ -124,7 +126,7 @@ withEnv action = do
124126
let pgConnectionMaxIdleTime = Time.secondsToDiffTime (60 * 5) -- 5 minutes
125127
-- Limiting max lifetime helps cycle connections which may have accumulated memory cruft.
126128
let pgConnectionMaxLifetime = Time.secondsToDiffTime (60 * 60) -- 1 hour
127-
let pgSettings = Pool.settings [Pool.staticConnectionSettings (Text.encodeUtf8 postgresConfig), Pool.size postgresConnMax, Pool.acquisitionTimeout pgConnectionAcquisitionTimeout, Pool.idlenessTimeout pgConnectionMaxIdleTime, Pool.agingTimeout pgConnectionMaxLifetime]
129+
let pgSettings = Pool.settings [Pool.staticConnectionSettings postgresConfig, Pool.size postgresConnMax, Pool.acquisitionTimeout pgConnectionAcquisitionTimeout, Pool.idlenessTimeout pgConnectionMaxIdleTime, Pool.agingTimeout pgConnectionMaxLifetime]
128130
pgConnectionPool <- Pool.acquire pgSettings
129131
timeCache <- FL.newTimeCache FL.simpleTimeFormat -- E.g. 05/Sep/2023:13:23:56 -0700
130132
sandboxedRuntime <- RT.startRuntime True RT.Persistent "share"

share-api/src/Share/Env/Types.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ where
66

77
import Crypto.JOSE.JWK qualified as JWK
88
import Database.Redis qualified as R
9+
import Hasql.Connection qualified as Hasql
910
import Hasql.Pool qualified as Hasql
1011
import Network.HTTP.Client qualified as HTTPClient
1112
import Network.URI (URI)
@@ -43,7 +44,7 @@ data Env ctx = Env
4344
proxiedHttpClient :: HTTPClient.Manager,
4445
serverPort :: Int,
4546
redisConfig :: R.ConnectInfo,
46-
postgresConfig :: Text,
47+
postgresConfig :: Hasql.Settings,
4748
githubClientID :: Text,
4849
githubClientSecret :: Text,
4950
jwtSettings :: JWT.JWTSettings,

share-api/src/Share/IDs.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -520,9 +520,9 @@ newtype ReleaseId = ReleaseId UUID
520520
-- | Version for a release, e.g. "1.2.3". See also ReleaseShortHand which includes the
521521
-- 'releases/' prefix.
522522
data ReleaseVersion = ReleaseVersion
523-
{ major :: !Int64,
524-
minor :: !Int64,
525-
patch :: !Int64
523+
{ major :: !Int32,
524+
minor :: !Int32,
525+
patch :: !Int32
526526
}
527527
deriving stock (Eq, Ord, Show, Generic)
528528
deriving (FromHttpApiData, ToHttpApiData, ToJSON, FromJSON) via UsingID ReleaseVersion

share-api/src/Share/Notifications/Queries.hs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import Data.Foldable qualified as Foldable
3333
import Data.Ord (clamp)
3434
import Data.Set qualified as Set
3535
import Data.Set.NonEmpty (NESet)
36+
import Data.Time (UTCTime)
3637
import Share.Contribution
3738
import Share.IDs
3839
import Share.Notifications.API (GetHubEntriesCursor)
@@ -466,9 +467,9 @@ hydrateEventPayload = \case
466467
commentAuthor
467468
}
468469
construct
469-
<$> ( queryExpect1Row
470+
<$> ( queryExpect1Row @(CommentId, Text, UTCTime)
470471
[sql|
471-
SELECT cc.comment_id, cc.content, cc.created_at, cc.updated_at
472+
SELECT cc.comment_id, cc.content, cc.created_at
472473
FROM comment_content cc
473474
JOIN users author ON cc.author_id = author.id
474475
WHERE cc.comment_id = #{commentId}

share-api/src/Share/Postgres.hs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -264,17 +264,19 @@ data PostgresError
264264
deriving anyclass (Exception)
265265

266266
instance ToServerError PostgresError where
267-
toServerError (PostgresError err) =
268-
let errId = case err of
269-
Pool.ConnectionUsageError {} -> "connection-usage-error"
270-
Pool.SessionUsageError {} -> "session-usage-error"
271-
Pool.AcquisitionTimeoutUsageError {} -> "acquisition-timeout-usage-error"
272-
in (ErrorID $ "postgres:pool:" <> errId, internalServerError)
267+
toServerError = \case
268+
(PostgresError err) ->
269+
let errId = case err of
270+
Pool.ConnectionUsageError {} -> "connection-usage-error"
271+
Pool.SessionUsageError {} -> "session-usage-error"
272+
Pool.AcquisitionTimeoutUsageError {} -> "acquisition-timeout-usage-error"
273+
in (ErrorID $ "postgres:pool:" <> errId, internalServerError)
273274

274275
instance Logging.Loggable PostgresError where
275-
toLog (PostgresError err) =
276-
Logging.showLog err
277-
& Logging.withSeverity Logging.Error
276+
toLog = \case
277+
(PostgresError err) ->
278+
Logging.showLog err
279+
& Logging.withSeverity Logging.Error
278280

279281
-- TODO: I think we want to vary this per transaction.
280282
defaultIsolationLevel :: IsolationLevel

share-api/src/Share/Postgres/Causal/Queries.hs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -904,12 +904,12 @@ expectNamespaceStatsOf trav s =
904904
|]
905905
<&> fmap \(containedTerms, deepContainedTerms, containedTypes, deepContainedTypes, containedConstructors, deepContainedConstructors) ->
906906
NamespaceStats
907-
{ containedTerms = fromIntegral @Int64 @Int containedTerms,
908-
deepContainedTerms = fromIntegral @Int64 @Int deepContainedTerms,
909-
containedTypes = fromIntegral @Int64 @Int containedTypes,
910-
deepContainedTypes = fromIntegral @Int64 @Int deepContainedTypes,
911-
containedConstructors = fromIntegral @Int64 @Int containedConstructors,
912-
deepContainedConstructors = fromIntegral @Int64 @Int deepContainedConstructors
907+
{ containedTerms = fromIntegral @Int32 @Int containedTerms,
908+
deepContainedTerms = fromIntegral @Int32 @Int deepContainedTerms,
909+
containedTypes = fromIntegral @Int32 @Int containedTypes,
910+
deepContainedTypes = fromIntegral @Int32 @Int deepContainedTypes,
911+
containedConstructors = fromIntegral @Int32 @Int containedConstructors,
912+
deepContainedConstructors = fromIntegral @Int32 @Int deepContainedConstructors
913913
}
914914
if length results /= length branchHashes
915915
then unrecoverableError $ MissingExpectedEntity ("namespaceStatsOf: Expected namespace stats for all hashes: " <> tShow branchHashes)
@@ -992,7 +992,7 @@ isFastForward fromCausalId toCausalId = do
992992

993993
type CausalHistoryCursor = (CausalHash, CausalDepth)
994994

995-
type CausalDepth = Int64
995+
type CausalDepth = Int32
996996

997997
pagedCausalAncestors ::
998998
(QueryM m) =>

share-api/src/Share/Postgres/Definitions/Queries.hs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ import Data.ByteString.Lazy.Char8 qualified as BL
5454
import Data.List.NonEmpty qualified as NE
5555
import Data.List.NonEmpty qualified as NonEmpty
5656
import Data.Set qualified as Set
57-
import Data.Text qualified as Text
5857
import Data.Vector qualified as Vector
5958
import Hasql.Decoders qualified as Decoders
6059
import Hasql.Interpolate qualified as Hasql
@@ -627,7 +626,7 @@ constructorReferentsByPrefix ::
627626
constructorReferentsByPrefix prefix mayComponentIndex mayConstructorIndex = do
628627
let mayComponentIndex' = pgComponentIndex <$> mayComponentIndex
629628
let mayConstructorIndex' = pgConstructorIndex <$> mayConstructorIndex
630-
queryListRows @(Hash, PgComponentIndex, Text, PgConstructorIndex)
629+
queryListRows @(Hash, PgComponentIndex, DeclKindEnum, PgConstructorIndex)
631630
[sql| SELECT component_hashes.base32, typ.component_index, typ.kind, constr.constructor_index
632631
FROM component_hashes
633632
JOIN types typ ON component_hashes.id = typ.component_hash_id
@@ -640,9 +639,8 @@ constructorReferentsByPrefix prefix mayComponentIndex mayConstructorIndex = do
640639
<&> fmap
641640
( \(hash, componentIndex, declKind, constructorIndex) ->
642641
let dt = case declKind of
643-
"data" -> CT.Data
644-
"ability" -> CT.Effect
645-
kind -> error $ "declReferentsByPrefix: Unknown decl kind: " <> Text.unpack kind
642+
Data -> CT.Data
643+
Ability -> CT.Effect
646644
conRef = V1Referent.ConstructorReference (V1Reference.Derived hash (unPgComponentIndex componentIndex)) (unPgConstructorIndex constructorIndex)
647645
in V1Referent.Con conRef dt
648646
)

share-api/src/Share/Postgres/Definitions/Types.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ import U.Codebase.Sqlite.Term.Format qualified as TermFormat
4040
import Unison.ConstructorType qualified as CT
4141

4242
-- | Type wrappers for keeping indexes straight
43-
newtype PgComponentIndex = PgComponentIndex Int64
43+
newtype PgComponentIndex = PgComponentIndex Int32
4444
deriving newtype (Show, Eq, Ord, EncodeValue, DecodeValue)
4545

4646
pgComponentIndex :: Reference.Pos -> PgComponentIndex
@@ -49,7 +49,7 @@ pgComponentIndex = PgComponentIndex . fromIntegral
4949
unPgComponentIndex :: PgComponentIndex -> Reference.Pos
5050
unPgComponentIndex (PgComponentIndex i) = fromIntegral i
5151

52-
newtype PgConstructorIndex = PgConstructorIndex Int64
52+
newtype PgConstructorIndex = PgConstructorIndex Int32
5353
deriving newtype (Show, Eq, Ord, EncodeValue, DecodeValue)
5454

5555
pgConstructorIndex :: DD.ConstructorId -> PgConstructorIndex

0 commit comments

Comments
 (0)