Moved tag filter modes to postgres function.

This commit is contained in:
DebaucheryLibrarian 2020-07-19 04:25:07 +02:00
parent cf999896d5
commit 70bf00e844
3 changed files with 15 additions and 18 deletions

View File

@ -18,7 +18,7 @@
<select
v-model="mode"
class="mode"
@change="$router.push({ query: { ...$route.query, mode } })"
@change="$router.push({ query: { ...$route.query, mode }, params: { pageNumber: 1 } })"
>
<option
value="all"
@ -37,7 +37,7 @@
class="tag"
:class="{ selected: selectedTags.includes(tag.slug) }"
>
<router-link :to="{ query: { ...getNewRange(tag.slug), mode } }">
<router-link :to="{ query: { ...getNewRange(tag.slug), mode }, params: { pageNumber: 1 } }">
<Icon
icon="checkmark"
class="include"
@ -88,7 +88,7 @@ export default {
},
data() {
return {
mode: 'all',
mode: this.$route.query.mode || 'all',
};
},
computed: {

View File

@ -25,6 +25,7 @@ function initActorActions(store, router) {
$orderBy:[ReleasesOrderBy!]
$selectableTags: [String],
$includeTags: [String!],
$mode: String!,
) {
actor(id: $actorId) {
id
@ -151,19 +152,9 @@ function initActorActions(store, router) {
lessThan: $before,
greaterThan: $after,
}
${mode === 'any' ? `
releasesTagsConnection: {
some: {
tag: {
slug: {
in: $includeTags
}
}
}
}
` : ''}
}
${mode === 'all' ? 'selectedTags: $includeTags' : ''}
selectedTags: $includeTags
mode: $mode
first: $limit
offset: $offset
orderBy: $orderBy
@ -185,6 +176,7 @@ function initActorActions(store, router) {
orderBy,
excludeTags: store.state.ui.filter,
includeTags,
mode,
});
return {

View File

@ -857,7 +857,7 @@ exports.up = knex => Promise.resolve()
ORDER BY tags.name;
$$ LANGUAGE SQL STABLE;
CREATE FUNCTION actors_scenes(actor actors, selected_tags text[]) RETURNS SETOF releases AS $$
CREATE FUNCTION actors_scenes(actor actors, selected_tags text[], mode text DEFAULT 'all') RETURNS SETOF releases AS $$
SELECT releases.*
FROM releases
LEFT JOIN
@ -869,10 +869,15 @@ exports.up = knex => Promise.resolve()
LEFT JOIN
tags ON tags.id = releases_tags.tag_id
WHERE actors.id = actor.id
AND CASE
WHEN mode = 'any' AND array_length(selected_tags, 1) > 0
THEN tags.slug = ANY(selected_tags)
ELSE true
END
GROUP BY releases.id
HAVING CASE
WHEN array_length(selected_tags, 1) > 0
THEN COUNT(
WHEN mode = 'all' AND array_length(selected_tags, 1) > 0
THEN COUNT(
CASE WHEN tags.slug = ANY(selected_tags)
THEN true
END