Skip to content

Commit

Permalink
[NO-ISSUE] Sort and limit the amount of releases in the DB instead of…
Browse files Browse the repository at this point in the history
… Flora (#567)
  • Loading branch information
tchoutri authored Jul 24, 2024
1 parent af02dbb commit 8cc371d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 15 deletions.
2 changes: 2 additions & 0 deletions changelog.d/567
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
prs: #567
synopsis: Sort and limit the amount of releases in the DB instead of Flora
1 change: 0 additions & 1 deletion flora.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,6 @@ library
, utf8-string
, uuid
, vector
, vector-algorithms
, zlib

library flora-web
Expand Down
23 changes: 9 additions & 14 deletions src/core/Flora/Model/Release/Query.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,39 +20,37 @@ module Flora.Model.Release.Query
where

import Control.Monad (join)
import Data.ByteString (fromStrict)
import Data.ByteString.Lazy (LazyByteString)
import Data.Text (Text)
import Data.Time (UTCTime)
import Data.Vector (Vector)
import Data.Vector qualified as Vector
import Data.Vector.Algorithms.Intro as MVector
import Database.PostgreSQL.Entity
import Database.PostgreSQL.Entity.DBT (QueryNature (..), query, queryOne, queryOne_, query_)
import Database.PostgreSQL.Entity.Types (field)
import Database.PostgreSQL.Simple (In (..), Only (..), Query)
import Database.PostgreSQL.Simple.SqlQQ (sql)
import Database.PostgreSQL.Simple.SqlQQ
import Distribution.Orphans.Version ()
import Distribution.Version (Version)
import Effectful
import Effectful.PostgreSQL.Transact.Effect (DB, dbtToEff)

import Data.ByteString (fromStrict)
import Data.ByteString.Lazy (LazyByteString)
import Distribution.Orphans.Version ()
import Flora.Model.BlobStore.API (BlobStoreAPI, get)
import Flora.Model.BlobStore.Types
import Flora.Model.Component.Types
import Flora.Model.Package.Types
import Flora.Model.Release.Types

packageReleasesQuery :: Query
packageReleasesQuery = _selectWhere @Release [[field| package_id |]]
packageReleasesQuery =
_selectWhere @Release [[field| package_id |]]
<> " ORDER BY releases.version DESC "

getReleases :: DB :> es => PackageId -> Eff es (Vector Release)
getReleases pid =
dbtToEff $ do
results <- query Select packageReleasesQuery (Only pid)
if Vector.null results
then pure results
else pure $ Vector.take 6 $ Vector.reverse $ Vector.modify MVector.sort results
query Select (packageReleasesQuery <> " LIMIT 6") (Only pid)

getLatestReleaseTime :: DB :> es => Maybe Text -> Eff es (Maybe UTCTime)
getLatestReleaseTime repo =
Expand All @@ -79,10 +77,7 @@ getReleaseTarballArchive releaseId = do
getAllReleases :: DB :> es => PackageId -> Eff es (Vector Release)
getAllReleases pid =
dbtToEff $ do
results <- query Select packageReleasesQuery (Only pid)
if Vector.null results
then pure results
else pure $ Vector.reverse $ Vector.modify MVector.sort results
query Select packageReleasesQuery (Only pid)

getVersionFromManyReleaseIds
:: DB :> es
Expand Down

0 comments on commit 8cc371d

Please sign in to comment.