Skip to content

Commit

Permalink
Tags feature: replace some clumsy code
Browse files Browse the repository at this point in the history
  • Loading branch information
andreasabel committed Jul 2, 2024
1 parent 66e7c9e commit c7f3edd
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions src/Distribution/Server/Features/Tags/State.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ import Control.Monad (liftM2)
import Data.SafeCopy (base, deriveSafeCopy)
import Data.Typeable (Typeable)
import qualified Data.Char as Char
import Data.Functor ( (<&>) )
import Data.Maybe (fromMaybe)
import Data.List (foldl')
import Data.List (find, foldl')
import Control.Monad.State (get, put, modify)
import Control.Monad.Reader (ask, asks)
import Control.DeepSeq
Expand Down Expand Up @@ -87,13 +88,9 @@ lookupTagAlias tag
return (Map.lookup tag m)

getTagAlias :: Tag -> Query TagAlias Tag
getTagAlias tag
= do TagAlias m <- ask
if tag `elem` Map.keys m
then return tag
else if tag `Set.member` foldr Set.union Set.empty (Map.elems m)
then return $ head (Map.keys $ Map.filter (tag `Set.member`) m)
else return tag
getTagAlias tag = ask <&> \ (TagAlias m) ->
if Map.member tag m then tag
else maybe tag fst $ find (Set.member tag . snd) $ Map.toList m

emptyPackageTags :: PackageTags
emptyPackageTags = PackageTags Map.empty Map.empty Map.empty
Expand Down Expand Up @@ -279,4 +276,3 @@ $(makeAcidic ''PackageTags ['tagsForPackage
,'lookupReviewTags
,'clearReviewTags
])

0 comments on commit c7f3edd

Please sign in to comment.