use sets for tags

This commit is contained in:
rhiannon morris 2024-11-04 00:55:07 +01:00
parent b9b0edc173
commit 34bd2214f5
4 changed files with 19 additions and 17 deletions

View file

@ -41,7 +41,7 @@ import qualified Data.Map.Strict as Map
import Data.Set (Set, (\\))
import qualified Data.Set as Set
import Data.Maybe (isJust, isNothing, fromMaybe, mapMaybe, catMaybes)
import Data.List (nub, sortBy)
import Data.List (sortBy)
import Data.List.NonEmpty (NonEmpty (..), toList, nonEmpty)
import Data.Ord (comparing)
import Data.String (IsString)
@ -69,8 +69,8 @@ data Info =
galleryTitle :: !(Maybe Text),
artist :: !(Maybe Artist), -- nothing = me, obv
nsfwOnly :: !Bool,
tags :: ![Text],
nsfwTags :: ![Text],
tags :: !(HashSet Text),
nsfwTags :: !(HashSet Text),
desc :: !Desc,
nsfwDesc :: !Desc,
bg :: !Bg,
@ -246,8 +246,8 @@ instance HasField "exists" Desc Bool where
descFor :: Bool -> Info -> Desc
descFor nsfw (Info {desc, nsfwDesc}) = if nsfw then desc <> nsfwDesc else desc
tagsFor :: Bool -> Info -> [Text]
tagsFor nsfw i = if nsfw then nub $ i.tags <> i.nsfwTags else i.tags
tagsFor :: Bool -> Info -> HashSet Text
tagsFor nsfw i = if nsfw then i.tags <> i.nsfwTags else i.tags
imagesFor :: Bool -> Info -> Maybe Images
imagesFor nsfw i = if nsfw then Just i.images else sfwImages i
@ -488,9 +488,8 @@ noFilters =
matchFilters :: GalleryFilters -> Info -> Bool
matchFilters (GalleryFilters {nsfw, artist, require, exclude}) i =
matchNsfw nsfw i && matchArtist artist i &&
all (\t -> HashSet.member t tags) require &&
all (\t -> not $ HashSet.member t tags) exclude
where tags = HashSet.fromList i.tags
all (\t -> HashSet.member t i.tags) require &&
all (\t -> not $ HashSet.member t i.tags) exclude
instance FromYAML GalleryInfo where