From cb9cf4e6575052bf083b3cdff8fe6a7d7c4df28d Mon Sep 17 00:00:00 2001 From: FrenchGithubUser Date: Thu, 6 Nov 2025 19:57:47 +0100 Subject: [PATCH] fix: fix inconsistencies on the torrent search --- .../migrations/20250312215600_initdb.sql | 10 ++++++++ .../src/repositories/torrent_repository.rs | 18 +++++++++++-- .../torrent/TorrentSearchInputs.vue | 20 ++++++++++----- frontend/src/views/TorrentSearchView.vue | 25 ++++++++++++++----- 4 files changed, 59 insertions(+), 14 deletions(-) diff --git a/backend/storage/migrations/20250312215600_initdb.sql b/backend/storage/migrations/20250312215600_initdb.sql index 69890382..5bec5f27 100644 --- a/backend/storage/migrations/20250312215600_initdb.sql +++ b/backend/storage/migrations/20250312215600_initdb.sql @@ -909,6 +909,11 @@ SELECT t.video_resolution, t.video_resolution_other_x, t.video_resolution_other_y, + (EXISTS ( + SELECT 1 + FROM torrent_reports tr + WHERE tr.reported_torrent_id = t.id + )) AS reported, CASE WHEN EXISTS (SELECT 1 FROM torrent_reports WHERE reported_torrent_id = t.id) THEN json_agg(row_to_json(tr)) ELSE '[]'::json @@ -1091,3 +1096,8 @@ create trigger refresh_materialized_view_title_group_hierarchy_lite after insert or update or delete or truncate on title_groups for each statement execute procedure refresh_materialized_view_title_group_hierarchy_lite(); + +create trigger refresh_materialized_view_title_group_hierarchy_lite +after insert or update or delete or truncate +on torrent_reports for each statement +execute procedure refresh_materialized_view_title_group_hierarchy_lite(); diff --git a/backend/storage/src/repositories/torrent_repository.rs b/backend/storage/src/repositories/torrent_repository.rs index 9a43d9f2..d87029aa 100644 --- a/backend/storage/src/repositories/torrent_repository.rs +++ b/backend/storage/src/repositories/torrent_repository.rs @@ -587,10 +587,24 @@ impl ConnectionPool { COALESCE(extras, '{}') AS "extras!: _" FROM torrents_and_reports tar WHERE edition_group_id = ANY($1) - AND ($2::INT IS NULL OR tar.created_by_id = $2) + + AND ($3::BOOLEAN IS NULL OR tar.staff_checked = $3) + AND ($4::BOOLEAN IS NULL OR tar.reported = $4) + AND ( + $2::INT IS NULL OR + -- don't return torrents created as anonymous + -- unless the requesting user is the uploader + (tar.created_by_id = $2 AND ( + tar.created_by_id = $5 OR + NOT tar.uploaded_as_anonymous) + ) + ) "#, &edition_group_ids, - form.torrent_created_by_id + form.torrent_created_by_id, + form.torrent_staff_checked, + form.torrent_reported, + requesting_user_id, ) .fetch_all(self.borrow()) .await?; diff --git a/frontend/src/components/torrent/TorrentSearchInputs.vue b/frontend/src/components/torrent/TorrentSearchInputs.vue index a6487c4e..0665e8db 100644 --- a/frontend/src/components/torrent/TorrentSearchInputs.vue +++ b/frontend/src/components/torrent/TorrentSearchInputs.vue @@ -87,6 +87,7 @@ import { Dropdown, InputNumber } from 'primevue' import type { TorrentSearch } from '@/services/api/torrentService' import { onMounted } from 'vue' import { useRouter } from 'vue-router' +import { watch } from 'vue' const { t } = useI18n() const router = useRouter() @@ -96,15 +97,11 @@ const props = defineProps<{ initialForm: TorrentSearch }>() -const emit = defineEmits<{ - search: [form: TorrentSearch] -}>() - const sortByOptions = ref([ { label: t('torrent.created_at'), value: 'torrent_created_at' }, { label: t('torrent.size'), value: 'torrent_size' }, { label: t('title_group.original_release_date'), value: 'title_group_original_release_date' }, - { label: t('torrent.snatched_at'), value: 'torrent_snatched_at' }, + // { label: t('torrent.snatched_at'), value: 'torrent_snatched_at' }, ]) const orderOptions = [ { label: t('general.ascending'), value: 'asc' }, @@ -134,7 +131,7 @@ const changePage = (page: number) => { } const search = () => { router.push({ query: searchForm.value }) - emit('search', searchForm.value) + // a search will be triggered by the query changes through a watcher } defineExpose({ searchForm, @@ -144,6 +141,17 @@ defineExpose({ onMounted(async () => { searchForm.value = props.initialForm }) + +watch( + () => searchForm.value, + (newVal, oldVal) => { + // ignore if only `page` changed + if (newVal.page === oldVal.page) { + searchForm.value.page = 1 + } + }, + { deep: true }, +)