Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NO-ISSUE] Show last upload or revision date in package listings #580

Merged
merged 1 commit into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions app/cli/DesignSystem.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import Data.Foldable (forM_)
import Data.Functor.Identity (runIdentity)
import Data.Text (Text)
import Data.Text.Lazy qualified as TL
import Data.Time.Calendar.OrdinalDate as Time
import Data.Time.Clock (UTCTime (..))
import Data.UUID qualified as UUID
import Data.Vector (Vector)
import Data.Vector qualified as Vector
Expand Down Expand Up @@ -100,6 +102,8 @@ packageListItemExample =
, "Basic libraries"
, mkVersion [4, 16, 0, 0]
, License (simpleLicenseExpression BSD_3_Clause)
, Just $ UTCTime (Time.fromMondayStartWeek 2024 32 1) 0
, Just $ UTCTime (Time.fromMondayStartWeek 2024 60 15) 0
)

categoryCardExample :: FloraHTML
Expand Down
2 changes: 1 addition & 1 deletion assets/css/3-screens/1-package/1-package.css
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,12 @@ span.revised-date::before {
color: #fff;
padding: 5px;
text-align: center;
width: 200px;
display: none; /* hide by default */
}

span.revised-date:hover::before {
display: block;
width: 200px;
}

.revised-date {
Expand Down
4 changes: 2 additions & 2 deletions cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ allow-older: pg-entity:time
test-show-details: direct

package *
ghc-options: "-L /usr/pgsql-14/lib" +RTS -A32m -RTS -j -haddock
ghc-options: "-L /usr/pgsql-14/lib" +RTS -A32m -RTS -j

package warp
flags: -x509
Expand All @@ -32,7 +32,7 @@ package zlib
source-repository-package
type: git
location: https://github.com/scrive/tracing
tag: e49720d
tag: 9c2baa1
subdir:
.
./tracing-effectful
Expand Down
1 change: 1 addition & 0 deletions flora.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,7 @@ executable flora-cli
, sel
, text
, text-display
, time
, transformers
, uuid
, vector
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
DROP MATERIALIZED VIEW latest_versions;

CREATE MATERIALIZED VIEW latest_versions (namespace, name, synopsis, package_id, version, license, uploaded_at, revised_at)
AS SELECT DISTINCT ON (p.package_id) p.namespace
, p.name
, r.synopsis
, p.package_id
, r.version
, r.license
, r.uploaded_at
, r.revised_at
FROM packages AS p
INNER JOIN releases AS r ON p.package_id = r.package_id
WHERE p.status = 'fully-imported'
AND r.deprecated IS DISTINCT FROM TRUE
GROUP BY p.namespace, p.name, synopsis, p.package_id, r.version, license, r.uploaded_at, r.revised_at
ORDER BY p.package_id
, version DESC;

CREATE INDEX
ON latest_versions (name);

CREATE INDEX
ON latest_versions (namespace
, name);

CREATE UNIQUE INDEX
ON latest_versions (name
, namespace
, version)
30 changes: 29 additions & 1 deletion src/core/Flora/Model/Package/Query.hs
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,8 @@ WITH dependents AS (
, r.version
, r.synopsis
, r.license
, r.uploaded_at
, r.revised_at
FROM packages AS p
INNER JOIN dependents AS dep ON p.package_id = dep.dependent_id
INNER JOIN releases AS r ON r.package_id = p.package_id
Expand All @@ -252,6 +254,8 @@ SELECT d.namespace
, d.version
, d.synopsis
, d.license
, d.uploaded_at
, d.revised_at
FROM dependents AS d
WHERE rank = 1
|]
Expand All @@ -268,6 +272,8 @@ WITH dependents AS (
, r.version
, r.synopsis
, r.license
, r.uploaded_at
, r.revised_at
FROM packages AS p
INNER JOIN dependents AS dep ON p.package_id = dep.dependent_id
INNER JOIN releases AS r ON r.package_id = p.package_id
Expand All @@ -281,6 +287,8 @@ SELECT d.namespace
, d.version
, d.synopsis
, d.license
, d.uploaded_at
, d.revised_at
FROM dependents AS d
WHERE rank = 1
|]
Expand Down Expand Up @@ -367,14 +375,16 @@ WITH requirements AS (SELECT DISTINCT p1.component_type
, r3.version AS dependency_latest_version
, r3.synopsis AS dependency_latest_synopsis
, r3.license AS dependency_latest_license
, r3.uploaded_at
, r3.revised_at
FROM requirements AS req
INNER JOIN packages AS p2 ON p2.namespace = req.namespace
AND p2.name = req.name
INNER JOIN releases AS r3 ON r3.package_id = p2.package_id
WHERE r3.version = (SELECT max(version)
FROM releases
WHERE package_id = p2.package_id)
GROUP BY req.component_type, req.component_name, req.namespace, req.name, req.requirement, req.components, r3.version, r3.synopsis, r3.license
GROUP BY req.component_type, req.component_name, req.namespace, req.name, req.requirement, req.components, r3.version, r3.synopsis, r3.license, r3.uploaded_at, r3.revised_at
ORDER BY req.component_type
, req.component_name DESC
|]
Expand Down Expand Up @@ -471,6 +481,8 @@ getPackagesFromCategoryWithLatestVersion categoryId = dbtToEff $ query Select q
, lv.version
, lv.license
, 1
, lv.uploaded_at
, lv.revised_at
from latest_versions as lv
inner join package_categories as p1 on p1.package_id = lv.package_id
inner join categories as c2 on c2.category_id = p1.category_id
Expand All @@ -493,6 +505,8 @@ searchPackage (offset, limit) searchString =
, lv."version"
, lv."license"
, word_similarity(lv.name, ?) as rating
, lv."uploaded_at"
, lv."revised_at"
FROM latest_versions as lv
WHERE ? <% lv.name
GROUP BY
Expand All @@ -501,6 +515,8 @@ searchPackage (offset, limit) searchString =
, lv."synopsis"
, lv."version"
, lv."license"
, lv."uploaded_at"
, lv."revised_at"
ORDER BY rating desc, count(lv."namespace") desc, lv.name asc
OFFSET ?
LIMIT ?
Expand All @@ -525,6 +541,8 @@ searchPackageByNamespace (offset, limit) namespace searchString =
, lv."version"
, lv."license"
, word_similarity(lv.name, ?) as rating
, lv."uploaded_at"
, lv."revised_at"
FROM latest_versions as lv
WHERE
? <% lv."name"
Expand All @@ -535,6 +553,8 @@ searchPackageByNamespace (offset, limit) namespace searchString =
, lv."synopsis"
, lv."version"
, lv."license"
, lv."uploaded_at"
, lv."revised_at"
ORDER BY rating desc, count(lv."namespace") desc, lv.name asc
LIMIT ?
OFFSET ?
Expand Down Expand Up @@ -629,13 +649,17 @@ listAllPackages (offset, limit) =
, lv."version"
, lv."license"
, (1.0::real) as rating
, lv."uploaded_at"
, lv."revised_at"
FROM latest_versions as lv
GROUP BY
lv."namespace"
, lv."name"
, lv."synopsis"
, lv."version"
, lv."license"
, lv."uploaded_at"
, lv."revised_at"
ORDER BY rating DESC
, COUNT(lv."namespace") DESC
, lv.name ASC
Expand All @@ -661,6 +685,8 @@ listAllPackagesInNamespace (offset, limit) namespace =
, lv."version"
, lv."license"
, (1.0::real) as rating
, lv."uploaded_at"
, lv."revised_at"
FROM latest_versions as lv
WHERE lv."namespace" = ?
GROUP BY
Expand All @@ -669,6 +695,8 @@ listAllPackagesInNamespace (offset, limit) namespace =
, lv."synopsis"
, lv."version"
, lv."license"
, lv."uploaded_at"
, lv."revised_at"
ORDER BY rating desc, lv."name" asc
OFFSET ?
LIMIT ?
Expand Down
2 changes: 2 additions & 0 deletions src/core/Flora/Model/Package/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,8 @@ data PackageInfo = PackageInfo
, version :: Version
, license :: SPDX.License
, rating :: Maybe Double
, uploadedAt :: Maybe UTCTime
, revisedAt :: Maybe UTCTime
}
deriving stock (Eq, Ord, Show, Generic)
deriving anyclass (FromRow, NFData)
Expand Down
5 changes: 5 additions & 0 deletions src/core/Flora/Model/Requirement.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import Control.DeepSeq
import Data.ByteString.Lazy (fromStrict)
import Data.Maybe (fromJust)
import Data.Text.Encoding (encodeUtf8)
import Data.Time (UTCTime)
import Deriving.Aeson
import Distribution.SPDX.License qualified as SPDX
import Distribution.Types.Version (Version)
Expand Down Expand Up @@ -68,6 +69,8 @@ data DependencyInfo = DependencyInfo
, latestVersion :: Version
, latestSynopsis :: Text
, latestLicense :: SPDX.License
, uploadedAt :: Maybe UTCTime
, revisedAt :: Maybe UTCTime
}
deriving stock (Eq, Show, Generic)
deriving anyclass (FromRow, NFData)
Expand All @@ -83,6 +86,8 @@ data ComponentDependency' = ComponentDependency'
, latestVersion :: Version
, latestSynopsis :: Text
, latestLicense :: SPDX.License
, uploadedAt :: Maybe UTCTime
, revisedAt :: Maybe UTCTime
}
deriving stock (Eq, Show, Generic)
deriving anyclass (FromRow, NFData)
Expand Down
2 changes: 2 additions & 0 deletions src/core/Flora/Search.hs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ dependencyInfoToPackageInfo dep =
dep.latestVersion
dep.latestLicense
Nothing
dep.uploadedAt
dep.revisedAt

listAllPackagesInNamespace
:: (DB :> es, Time :> es, Log :> es)
Expand Down
36 changes: 31 additions & 5 deletions src/web/FloraWeb/Components/PackageListItem.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,35 @@ import Data.List (intersperse, sortOn)
import Data.Map qualified as Map
import Data.Text (Text)
import Data.Text.Display (display)
import Data.Time (UTCTime, defaultTimeLocale)
import Data.Time qualified as Time
import Data.Vector qualified as Vector
import Distribution.SPDX.License qualified as SPDX
import Distribution.Types.Version (Version)
import FloraWeb.Pages.Templates (FloraHTML)
import Lucid
import Lucid.Orphans ()

import Distribution.SPDX.License qualified as SPDX
import Distribution.Types.Version (Version)
import Flora.Model.Component.Types (CanonicalComponent (..))
import Flora.Model.Package (ElemRating (..), Namespace, PackageInfoWithExecutables (..), PackageName (..))
import Flora.Model.Requirement
( ComponentDependencies
, DependencyInfo (..)
)
import FloraWeb.Components.Icons qualified as Icon
import Lucid.Orphans ()
import FloraWeb.Components.Utils

packageListItem :: (Namespace, PackageName, Text, Version, SPDX.License) -> FloraHTML
packageListItem (namespace, packageName, synopsis, version, license) = do
packageListItem
:: ( Namespace
, PackageName
, Text
, Version
, SPDX.License
, Maybe UTCTime
, Maybe UTCTime
)
-> FloraHTML
packageListItem (namespace, packageName, synopsis, version, license, mUploadedAt, mRevisedAt) = do
let href = href_ ("/packages/" <> display namespace <> "/" <> display packageName)
li_ [class_ "package-list-item"] $
a_ [href, class_ ""] $ do
Expand All @@ -41,6 +53,20 @@ packageListItem (namespace, packageName, synopsis, version, license) = do
Icon.license
toHtml license
span_ [class_ "package-list-item__version"] $ "v" <> toHtml version
case mUploadedAt of
Nothing -> ""
Just ts ->
span_ [] $ do
toHtml $ Time.formatTime defaultTimeLocale "%a, %_d %b %Y" ts
case mRevisedAt of
Nothing -> span_ [] ""
Just revisionDate ->
span_
[ dataText_
("Revised on " <> display (Time.formatTime defaultTimeLocale "%a, %_d %b %Y, %R %EZ" revisionDate))
, class_ "revised-date"
]
Icon.pen

packageWithExecutableListItem :: PackageInfoWithExecutables -> FloraHTML
packageWithExecutableListItem PackageInfoWithExecutables{namespace, name, synopsis, version, license, executables} = do
Expand Down
12 changes: 4 additions & 8 deletions src/web/FloraWeb/Pages/Server/Admin.hs
Original file line number Diff line number Diff line change
Expand Up @@ -57,26 +57,23 @@ fetchMetadataHandler (Headers session _) = do
forkIO $
Async.forConcurrently_
releasesWithoutReadme
( \(releaseId, version, packagename) -> scheduleReadmeJob jobsPool releaseId packagename version
)
(\(releaseId, version, packagename) -> scheduleReadmeJob jobsPool releaseId packagename version)

releasesWithoutUploadTime <- Query.getHackagePackageReleasesWithoutUploadTimestamp
liftIO $
void $
forkIO $
Async.forConcurrently_
releasesWithoutUploadTime
( \(releaseId, version, packagename) -> scheduleUploadTimeJob jobsPool releaseId packagename version
)
(\(releaseId, version, packagename) -> scheduleUploadTimeJob jobsPool releaseId packagename version)

releasesWithoutChangelog <- Query.getHackagePackageReleasesWithoutChangelog
liftIO $
void $
forkIO $
Async.forConcurrently_
releasesWithoutChangelog
( \(releaseId, version, packagename) -> scheduleChangelogJob jobsPool releaseId packagename version
)
(\(releaseId, version, packagename) -> scheduleChangelogJob jobsPool releaseId packagename version)

features <- ask @FeatureEnv
Log.logAttention "features" features
Expand All @@ -97,8 +94,7 @@ fetchMetadataHandler (Headers session _) = do
forkIO $ do
Async.forConcurrently_
packagesWithoutDeprecationInformation
( \a -> scheduleReleaseDeprecationListJob jobsPool a
)
(\a -> scheduleReleaseDeprecationListJob jobsPool a)
void $ scheduleRefreshLatestVersions jobsPool

pure $ redirect "/admin"
Loading
Loading