Fixed SQL total and pagination, showing end of result info. Hiding heart from scene tiles when not logged in.

This commit is contained in:
DebaucheryLibrarian 2024-03-17 22:15:11 +01:00
parent 3f36c0ae0a
commit 3238e678ef
6 changed files with 114 additions and 74 deletions

View File

@ -1,4 +1,10 @@
<template> <template>
<div class="pagination-container">
<div
v-if="currentPage === pageTotal && total > env.maxMatches"
class="more"
>Results are truncated, apply a filter to find more.</div>
<nav class="pagination"> <nav class="pagination">
<ul class="pages nolist"> <ul class="pages nolist">
<li> <li>
@ -76,6 +82,7 @@
</li> </li>
</ul> </ul>
</nav> </nav>
</div>
</template> </template>
<script setup> <script setup>
@ -103,18 +110,28 @@ const props = defineProps({
type: Boolean, type: Boolean,
default: true, default: true,
}, },
useMaxMatches: {
type: Boolean,
default: true,
},
}); });
const emit = defineEmits(['navigation']); const emit = defineEmits(['navigation']);
const pageContext = inject('pageContext'); const pageContext = inject('pageContext');
const { routeParams, urlParsed, pageProps } = pageContext;
const {
routeParams,
urlParsed,
pageProps,
env,
} = pageContext;
const currentPage = computed(() => props.page || Number(routeParams?.page)); const currentPage = computed(() => props.page || Number(routeParams?.page));
const limit = computed(() => props.limit || Number(pageProps.limit) || 30); const limit = computed(() => props.limit || Number(pageProps.limit) || 30);
const total = computed(() => props.total || Number(pageProps.total)); const total = computed(() => props.total || Number(pageProps.total));
const pageTotal = computed(() => Math.ceil(total.value / limit.value)); const pageTotal = computed(() => Math.ceil((props.useMaxMatches ? Math.min(total.value, env.maxMatches) : total.value) / limit.value));
const hasNextPage = computed(() => currentPage.value + 1 <= pageTotal.value); const hasNextPage = computed(() => currentPage.value + 1 <= pageTotal.value);
const hasPrevPage = computed(() => currentPage.value - 1 >= 1); const hasPrevPage = computed(() => currentPage.value - 1 >= 1);
@ -179,6 +196,12 @@ function getPath(page) {
</script> </script>
<style scoped> <style scoped>
.pagination-container {
display: flex;
flex-direction: column;
justify-content: center;
}
.pagination { .pagination {
height: 5rem; height: 5rem;
display: flex; display: flex;
@ -242,4 +265,11 @@ function getPath(page) {
.next { .next {
margin-left: .5rem; margin-left: .5rem;
} }
.more {
padding: 2rem;
text-align: center;
color: var(--shadow-strong-10);
font-size: 1.1rem;
}
</style> </style>

View File

@ -169,8 +169,6 @@ const scope = ref(routeParams.scope || props.defaultScope);
const total = ref(Number(pageProps.total)); const total = ref(Number(pageProps.total));
const loading = ref(false); const loading = ref(false);
console.log('SCOPE', routeParams.scope, scope.value);
const actorIds = urlParsed.search.actors?.split(',').map((identifier) => parseActorIdentifier(identifier)?.id).filter(Boolean) || []; const actorIds = urlParsed.search.actors?.split(',').map((identifier) => parseActorIdentifier(identifier)?.id).filter(Boolean) || [];
const queryActors = actorIds.map((urlActorId) => aggActors.value.find((aggActor) => aggActor.id === urlActorId)).filter(Boolean); const queryActors = actorIds.map((urlActorId) => aggActors.value.find((aggActor) => aggActor.id === urlActorId)).filter(Boolean);

View File

@ -28,7 +28,7 @@
/> />
<Icon <Icon
v-show="!favorited" v-show="!favorited && user"
icon="heart8" icon="heart8"
class="heart" class="heart"
@click.native.stop="stash" @click.native.stop="stash"

View File

@ -1,3 +1,4 @@
import config from 'config';
import { differenceInYears } from 'date-fns'; import { differenceInYears } from 'date-fns';
import { unit } from 'mathjs'; import { unit } from 'mathjs';
@ -272,6 +273,10 @@ export async function fetchActors(filters, rawOptions) {
sort: [{ country: { order: 'asc' } }], sort: [{ country: { order: 'asc' } }],
}, },
}, },
options: {
max_matches: config.database.manticore.maxMatches,
max_query_time: config.database.manticore.maxQueryTime,
},
}); });
const actorIds = result.hits.hits.map((hit) => Number(hit._id)); const actorIds = result.hits.hits.map((hit) => Number(hit._id));

View File

@ -377,7 +377,8 @@ async function queryManticoreSql(filters, options, _reqUser) {
max_query_time=:maxQueryTime: max_query_time=:maxQueryTime:
:actorsFacet: :actorsFacet:
:tagsFacet: :tagsFacet:
:channelsFacet: :channelsFacet:;
show meta;
`, { `, {
query: knexManticore(filters.stashId ? 'scenes_stashed' : 'scenes') query: knexManticore(filters.stashId ? 'scenes_stashed' : 'scenes')
.modify((builder) => { .modify((builder) => {
@ -459,6 +460,7 @@ async function queryManticoreSql(filters, options, _reqUser) {
} }
}) })
.limit(options.limit) .limit(options.limit)
.offset((options.page - 1) * options.limit)
.toString(), .toString(),
// option threads=1 fixes actors, but drastically slows down performance, wait for fix // option threads=1 fixes actors, but drastically slows down performance, wait for fix
actorsFacet: options.aggregateActors ? knex.raw('facet scenes.actor_ids order by count(*) desc limit ?', [aggSize]) : null, actorsFacet: options.aggregateActors ? knex.raw('facet scenes.actor_ids order by count(*) desc limit ?', [aggSize]) : null,
@ -496,9 +498,11 @@ async function queryManticoreSql(filters, options, _reqUser) {
?.data.map((row) => ({ key: row.channel_id || row['scenes.channel_id'], doc_count: row['count(*)'] })) ?.data.map((row) => ({ key: row.channel_id || row['scenes.channel_id'], doc_count: row['count(*)'] }))
|| []; || [];
const total = results.at(-1).data.find((entry) => entry.Variable_name === 'total_found').Value;
return { return {
scenes: results[0].data, scenes: results[0].data,
total: results[0].total, total,
aggregations: { aggregations: {
actorIds, actorIds,
tagIds, tagIds,
@ -546,6 +550,8 @@ export async function fetchScenes(filters, rawOptions, reqUser) {
const scenes = await fetchScenesById(sceneIds, reqUser); const scenes = await fetchScenesById(sceneIds, reqUser);
console.timeEnd('fetch full'); console.timeEnd('fetch full');
console.log('total', result.total);
return { return {
scenes, scenes,
aggActors, aggActors,

View File

@ -148,6 +148,7 @@ export default async function initServer() {
env: { env: {
allowLogin: config.auth.login, allowLogin: config.auth.login,
allowSignup: config.auth.signup, allowSignup: config.auth.signup,
maxMatches: config.database.manticore.maxMatches,
maxAggregateSize: config.database.manticore.maxAggregateSize, maxAggregateSize: config.database.manticore.maxAggregateSize,
}, },
}; };