Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
b60aa1b
(refactor) Import votesStore unqualified
tomjaguarpaw Jul 11, 2026
6fab880
(refactor) Move votesScore
tomjaguarpaw Jul 11, 2026
a42ddfd
(refactor) Move votesStateComponent
tomjaguarpaw Jul 11, 2026
89be368
(refactor) Introduce Votes abstraction layer
tomjaguarpaw Jul 11, 2026
335d985
(refactor) eta reduce
tomjaguarpaw Jul 11, 2026
84b9ed7
(whitespace) Unwrap lines
tomjaguarpaw Jul 11, 2026
cda516f
(refactor) Move platformStateComponent
tomjaguarpaw Jul 11, 2026
96c5d0e
(refactor) Introduce HaskellPlatform abstraction layer
tomjaguarpaw Jul 11, 2026
0bc50f6
(refactor) Move analyticsPixelsStateComponent
tomjaguarpaw Jul 11, 2026
003eb71
(refactor) Introduce AnalyticsPixels abstraction layer
tomjaguarpaw Jul 11, 2026
3d7a9e1
(refactor) Eta reduce
tomjaguarpaw Jul 11, 2026
7f77d62
(refactor) Move mirrorersStateComponent
tomjaguarpaw Jul 11, 2026
9a09ec9
(whitespace) Wrap lines
tomjaguarpaw Jul 11, 2026
c42ae9f
(refactor) Introduce Mirror abstraction layer
tomjaguarpaw Jul 11, 2026
cfefe83
(refactor) Introduce Core abstraction layer
tomjaguarpaw Jul 11, 2026
c24e238
(refactor) Introduce TarIndexCache abstraction layer
tomjaguarpaw Jul 11, 2026
fd6a90c
(refactor) Move packagesStateComponent
tomjaguarpaw Jul 11, 2026
cc27e63
(refactor) Introduce Core abstraction layer
tomjaguarpaw Jul 11, 2026
c8a2bad
(refactor) Pull out pkgs
tomjaguarpaw Jul 14, 2026
ddfa57c
Add package name lookup store query
tomjaguarpaw Jul 14, 2026
11eaf62
(refactor) Pull out mpkg
tomjaguarpaw Jul 14, 2026
bd6c29b
Add package ID lookup store query
tomjaguarpaw Jul 14, 2026
7792521
(refactor) Pull out PackageList add-hook pkgs
tomjaguarpaw Jul 14, 2026
ac4531b
(refactor) Pull out PackageList preferred-hook pkgs
tomjaguarpaw Jul 14, 2026
cc24df6
Use package name lookup query in list and search
tomjaguarpaw Jul 14, 2026
ff504c2
(refactor) Add Search pkgname let
tomjaguarpaw Jul 14, 2026
d5184c1
(refactor) Apply last earlier
tomjaguarpaw Jul 14, 2026
edaa970
(refactor) Extract latest package earlier
tomjaguarpaw Jul 14, 2026
baba666
(refactor) Pull out latestPackages
tomjaguarpaw Jul 14, 2026
85ab3aa
Add latest package versions query
tomjaguarpaw Jul 14, 2026
cc82bb1
(refactor) Run allPackageNames earlier
tomjaguarpaw Jul 15, 2026
6f39411
(refactor) Pull out pkgNames
tomjaguarpaw Jul 15, 2026
c1c740f
(refactor) Use queryLatestPackages instead of queryGetPackageIndex
tomjaguarpaw Jul 15, 2026
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
12 changes: 12 additions & 0 deletions hackage-server.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,9 @@ library
Distribution.Server.Features.Browse.Options
Distribution.Server.Features.Browse.Parsers
Distribution.Server.Features.Core
Distribution.Server.Features.Core.Acid
Distribution.Server.Features.Core.State
Distribution.Server.Features.Core.Store
Distribution.Server.Features.Core.Backup
Distribution.Server.Features.Security
Distribution.Server.Features.Security.Backup
Expand All @@ -320,6 +322,10 @@ library
Distribution.Server.Features.Security.SHA256
Distribution.Server.Features.Security.State
Distribution.Server.Features.Mirror
Distribution.Server.Features.Mirror.Acid
Distribution.Server.Features.Mirror.Store
Distribution.Server.Features.TarIndexCache.Acid
Distribution.Server.Features.TarIndexCache.Store
Distribution.Server.Features.Upload
Distribution.Server.Features.Upload.State
Distribution.Server.Features.Upload.Backup
Expand Down Expand Up @@ -370,7 +376,9 @@ library
Distribution.Server.Features.Html.HtmlUtilities
Distribution.Server.Features.HoogleData
Distribution.Server.Features.HaskellPlatform
Distribution.Server.Features.HaskellPlatform.Acid
Distribution.Server.Features.HaskellPlatform.State
Distribution.Server.Features.HaskellPlatform.Store
Distribution.Server.Features.PackageInfoJSON
Distribution.Server.Features.Search
Distribution.Server.Features.Search.BM25F
Expand All @@ -385,8 +393,10 @@ library
Distribution.Server.Features.Search.TermBag
Distribution.Server.Features.Sitemap.Functions
Distribution.Server.Features.Votes
Distribution.Server.Features.Votes.Acid
Distribution.Server.Features.Votes.Render
Distribution.Server.Features.Votes.State
Distribution.Server.Features.Votes.Store
Distribution.Server.Features.Votes.Types
Distribution.Server.Features.Vouch
Distribution.Server.Features.Vouch.State
Expand All @@ -403,7 +413,9 @@ library
Distribution.Server.Features.Tags.State
Distribution.Server.Features.Tags.Types
Distribution.Server.Features.AnalyticsPixels
Distribution.Server.Features.AnalyticsPixels.Acid
Distribution.Server.Features.AnalyticsPixels.State
Distribution.Server.Features.AnalyticsPixels.Store
Distribution.Server.Features.AnalyticsPixels.Types
Distribution.Server.Features.UserDetails
Distribution.Server.Features.UserDetails.Acid
Expand Down
38 changes: 10 additions & 28 deletions src/Distribution/Server/Features/AnalyticsPixels.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ module Distribution.Server.Features.AnalyticsPixels

import Data.Set (Set)

import Distribution.Server.Features.AnalyticsPixels.Acid (acidStore)
import qualified Distribution.Server.Features.AnalyticsPixels.Store as Store
import Distribution.Server.Features.AnalyticsPixels.Types
import qualified Distribution.Server.Features.AnalyticsPixels.State as Acid

import Distribution.Server.Framework
import Distribution.Server.Framework.BackupRestore

import Distribution.Server.Features.Core
import Distribution.Server.Features.Upload
Expand Down Expand Up @@ -53,7 +53,7 @@ initAnalyticsPixelsFeature :: ServerEnv
-> UploadFeature
-> IO AnalyticsPixelsFeature)
initAnalyticsPixelsFeature env@ServerEnv{serverStateDir} = do
dbAnalyticsPixelsState <- analyticsPixelsStateComponent serverStateDir
dbAnalyticsPixelsState <- acidStore serverStateDir
analyticsPixelAdded <- newHook
analyticsPixelRemoved <- newHook

Expand All @@ -64,27 +64,9 @@ initAnalyticsPixelsFeature env@ServerEnv{serverStateDir} = do

return feature

-- | Define the backing store (i.e. database component)
analyticsPixelsStateComponent :: FilePath -> IO (StateComponent AcidState Acid.AnalyticsPixelsState)
analyticsPixelsStateComponent stateDir = do
st <- openLocalStateFrom (stateDir </> "db" </> "AnalyticsPixels") Acid.initialAnalyticsPixelsState
return StateComponent {
stateDesc = "Backing store for AnalyticsPixels feature"
, stateHandle = st
, getState = query st Acid.GetAnalyticsPixelsState
, putState = update st . Acid.ReplaceAnalyticsPixelsState
, resetState = analyticsPixelsStateComponent
, backupState = \_ _ -> []
, restoreState = RestoreBackup {
restoreEntry = error "Unexpected backup entry"
, restoreFinalize = return Acid.initialAnalyticsPixelsState
}
}


-- | Default constructor for building this feature.
analyticsPixelsFeature :: ServerEnv
-> StateComponent AcidState Acid.AnalyticsPixelsState
-> Store.Backend
-> CoreFeature -- To get site package list
-> UserFeature -- To authenticate users
-> UploadFeature -- For accessing package maintainers and trustees
Expand All @@ -93,7 +75,7 @@ analyticsPixelsFeature :: ServerEnv
-> AnalyticsPixelsFeature

analyticsPixelsFeature ServerEnv{..}
analyticsPixelsState
Store.Backend{backendStore = analyticsPixelsState, backendState}
CoreFeature { coreResource = CoreResource{..} }
UserFeature{..}
UploadFeature{..}
Expand All @@ -104,7 +86,7 @@ analyticsPixelsFeature ServerEnv{..}
analyticsPixelsFeatureInterface = (emptyHackageFeature "AnalyticsPixels") {
featureDesc = "Allow users to attach analytics pixels to their packages",
featureResources = [analyticsPixelsResource, userAnalyticsPixelsResource]
, featureState = [abstractAcidStateComponent analyticsPixelsState]
, featureState = backendState
}

analyticsPixelsResource :: Resource
Expand All @@ -114,16 +96,16 @@ analyticsPixelsFeature ServerEnv{..}
userAnalyticsPixelsResource = resourceAt "/user/:username/analytics-pixels.:format"

getPackageAnalyticsPixels :: MonadIO m => PackageName -> m (Set AnalyticsPixel)
getPackageAnalyticsPixels name =
queryState analyticsPixelsState (Acid.AnalyticsPixelsForPackage name)
getPackageAnalyticsPixels =
Store.getPackageAnalyticsPixels analyticsPixelsState

addPackageAnalyticsPixel :: MonadIO m => PackageName -> AnalyticsPixel -> m Bool
addPackageAnalyticsPixel name pixel = do
added <- updateState analyticsPixelsState (Acid.AddPackageAnalyticsPixel name pixel)
added <- Store.addPackageAnalyticsPixel analyticsPixelsState name pixel
when added $ runHook_ analyticsPixelAdded (name, pixel)
pure added

removePackageAnalyticsPixel :: MonadIO m => PackageName -> AnalyticsPixel -> m ()
removePackageAnalyticsPixel name pixel = do
updateState analyticsPixelsState (Acid.RemovePackageAnalyticsPixel name pixel)
Store.removePackageAnalyticsPixel analyticsPixelsState name pixel
runHook_ analyticsPixelRemoved (name, pixel)
37 changes: 37 additions & 0 deletions src/Distribution/Server/Features/AnalyticsPixels/Acid.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
module Distribution.Server.Features.AnalyticsPixels.Acid
( acidStore
) where

import qualified Distribution.Server.Features.AnalyticsPixels.State as Acid
import Distribution.Server.Features.AnalyticsPixels.Store
import Distribution.Server.Framework
import Distribution.Server.Framework.BackupRestore

acidStore :: FilePath -> IO Backend
acidStore stateDir = do
analyticsPixelsState <- analyticsPixelsStateComponent stateDir
return Backend {
backendStore = Store {
getPackageAnalyticsPixels = \name -> queryState analyticsPixelsState (Acid.AnalyticsPixelsForPackage name)
, addPackageAnalyticsPixel = \name pixel -> updateState analyticsPixelsState (Acid.AddPackageAnalyticsPixel name pixel)
, removePackageAnalyticsPixel = \name pixel -> updateState analyticsPixelsState (Acid.RemovePackageAnalyticsPixel name pixel)
}
, backendState = [abstractAcidStateComponent analyticsPixelsState]
}

-- | Define the backing store (i.e. database component)
analyticsPixelsStateComponent :: FilePath -> IO (StateComponent AcidState Acid.AnalyticsPixelsState)
analyticsPixelsStateComponent stateDir = do
st <- openLocalStateFrom (stateDir </> "db" </> "AnalyticsPixels") Acid.initialAnalyticsPixelsState
return StateComponent {
stateDesc = "Backing store for AnalyticsPixels feature"
, stateHandle = st
, getState = query st Acid.GetAnalyticsPixelsState
, putState = update st . Acid.ReplaceAnalyticsPixelsState
, resetState = analyticsPixelsStateComponent
, backupState = \_ _ -> []
, restoreState = RestoreBackup {
restoreEntry = error "Unexpected backup entry"
, restoreFinalize = return Acid.initialAnalyticsPixelsState
}
}
25 changes: 25 additions & 0 deletions src/Distribution/Server/Features/AnalyticsPixels/Store.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{-# LANGUAGE RankNTypes #-}

module Distribution.Server.Features.AnalyticsPixels.Store
( Backend(..)
, Store(..)
) where

import Distribution.Server.Features.AnalyticsPixels.Types
import Distribution.Server.Framework (AbstractStateComponent)

import Distribution.Package (PackageName)

import Control.Monad.Trans (MonadIO)
import Data.Set (Set)

data Backend = Backend {
backendStore :: Store
, backendState :: [AbstractStateComponent]
}

data Store = Store {
getPackageAnalyticsPixels :: forall m. MonadIO m => PackageName -> m (Set AnalyticsPixel)
, addPackageAnalyticsPixel :: forall m. MonadIO m => PackageName -> AnalyticsPixel -> m Bool
, removePackageAnalyticsPixel :: forall m. MonadIO m => PackageName -> AnalyticsPixel -> m ()
}
Loading