From 8138c76a87dbec5381bf7d46c21b2c191cae303a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fernando=20Fern=C3=A1ndez?= Date: Sun, 29 Dec 2024 12:36:10 +0100 Subject: [PATCH] refactor: use parallel fetching when possible MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Fernando Fernández --- frontend/src/components/Item/SeasonTabs.vue | 56 ++---------- .../components/Layout/Artist/ArtistTab.vue | 5 +- .../src/components/Playback/TrackList.vue | 20 ++--- frontend/src/pages/artist/[itemId].vue | 88 ++++++++++++------- frontend/src/pages/genre/[itemId].vue | 27 +++--- frontend/src/pages/item/[itemId].vue | 27 +++--- frontend/src/pages/musicalbum/[itemId].vue | 26 ++++-- frontend/src/pages/person/[itemId].vue | 83 +++++++++-------- frontend/src/pages/search.vue | 43 ++++----- frontend/src/pages/series/[itemId].vue | 41 +++++++-- 10 files changed, 221 insertions(+), 195 deletions(-) diff --git a/frontend/src/components/Item/SeasonTabs.vue b/frontend/src/components/Item/SeasonTabs.vue index fe7bcac543a..edc6563beff 100644 --- a/frontend/src/components/Item/SeasonTabs.vue +++ b/frontend/src/components/Item/SeasonTabs.vue @@ -21,7 +21,7 @@ :lines="false" bg-color="transparent"> diff --git a/frontend/src/components/Layout/Artist/ArtistTab.vue b/frontend/src/components/Layout/Artist/ArtistTab.vue index 2346499c90d..16c6c9cae89 100644 --- a/frontend/src/components/Layout/Artist/ArtistTab.vue +++ b/frontend/src/components/Layout/Artist/ArtistTab.vue @@ -34,7 +34,9 @@ v-if="$vuetify.display.mdAndUp" class="my-2"> - + @@ -47,6 +49,7 @@ import type { BaseItemDto } from '@jellyfin/sdk/lib/generated-client'; import { getItemDetailsLink } from '@/utils/items'; const { releases } = defineProps<{ + tracks: BaseItemDto[]; releases: BaseItemDto[]; }>(); diff --git a/frontend/src/components/Playback/TrackList.vue b/frontend/src/components/Playback/TrackList.vue index 8966fde624f..a15fea7cd2d 100644 --- a/frontend/src/components/Playback/TrackList.vue +++ b/frontend/src/components/Playback/TrackList.vue @@ -115,28 +115,20 @@ diff --git a/frontend/src/pages/item/[itemId].vue b/frontend/src/pages/item/[itemId].vue index 80ceda5178d..6b534d4eb39 100644 --- a/frontend/src/pages/item/[itemId].vue +++ b/frontend/src/pages/item/[itemId].vue @@ -314,19 +314,26 @@ import { useItemPageTitle } from '@/composables/page-title'; const route = useRoute('/genre/[itemId]'); -const { data: item } = await useBaseItem(getUserLibraryApi, 'getItem')(() => ({ - itemId: route.params.itemId -})); -const { data: relatedItems } = await useBaseItem(getLibraryApi, 'getSimilarItems')(() => ({ - itemId: route.params.itemId, - limit: 12 -})); +const [ + { data: item }, + { data: relatedItems }, + { data: childItems } +] = await Promise.all([ + useBaseItem(getUserLibraryApi, 'getItem')(() => ({ + itemId: route.params.itemId + })), + useBaseItem(getLibraryApi, 'getSimilarItems')(() => ({ + itemId: route.params.itemId, + limit: 12 + })), + useBaseItem(getItemsApi, 'getItems')(() => ({ + parentId: route.params.itemId + })) +]); + const { data: currentSeries } = await useBaseItem(getUserLibraryApi, 'getItem')(() => ({ itemId: item.value.SeriesId ?? '' })); -const { data: childItems } = await useBaseItem(getItemsApi, 'getItems')(() => ({ - parentId: item.value.Id -})); const selectedSource = ref(); const currentVideoTrack = ref(); diff --git a/frontend/src/pages/musicalbum/[itemId].vue b/frontend/src/pages/musicalbum/[itemId].vue index 44f8c9def1b..7461370b827 100644 --- a/frontend/src/pages/musicalbum/[itemId].vue +++ b/frontend/src/pages/musicalbum/[itemId].vue @@ -90,7 +90,8 @@ + :item="item" + :tracks /> @@ -106,6 +107,8 @@ import { getLibraryApi } from '@jellyfin/sdk/lib/utils/api/library-api'; import { getUserLibraryApi } from '@jellyfin/sdk/lib/utils/api/user-library-api'; import { useRoute } from 'vue-router'; +import { getItemsApi } from '@jellyfin/sdk/lib/utils/api/items-api'; +import { SortOrder } from '@jellyfin/sdk/lib/generated-client'; import { getItemDetailsLink } from '@/utils/items'; import { useBaseItem } from '@/composables/apis'; import { useItemBackdrop } from '@/composables/backdrop'; @@ -113,13 +116,20 @@ import { useItemPageTitle } from '@/composables/page-title'; const route = useRoute('/musicalbum/[itemId]'); -const { data: item } = await useBaseItem(getUserLibraryApi, 'getItem')(() => ({ - itemId: route.params.itemId -})); -const { data: relatedItems } = await useBaseItem(getLibraryApi, 'getSimilarItems')(() => ({ - itemId: route.params.itemId, - limit: 5 -})); +const [{ data: item }, { data: relatedItems }, { data: tracks }] = await Promise.all([ + useBaseItem(getUserLibraryApi, 'getItem')(() => ({ + itemId: route.params.itemId + })), + useBaseItem(getLibraryApi, 'getSimilarItems')(() => ({ + itemId: route.params.itemId, + limit: 5 + })), + useBaseItem(getItemsApi, 'getItems')(() => ({ + parentId: route.params.itemId, + sortBy: ['SortName'], + sortOrder: [SortOrder.Ascending] + })) +]); useItemPageTitle(item); useItemBackdrop(item); diff --git a/frontend/src/pages/person/[itemId].vue b/frontend/src/pages/person/[itemId].vue index 3d64c8dea9f..4787d037040 100644 --- a/frontend/src/pages/person/[itemId].vue +++ b/frontend/src/pages/person/[itemId].vue @@ -174,7 +174,7 @@ import { getItemsApi } from '@jellyfin/sdk/lib/utils/api/items-api'; import { getLibraryApi } from '@jellyfin/sdk/lib/utils/api/library-api'; import { getUserLibraryApi } from '@jellyfin/sdk/lib/utils/api/user-library-api'; import { format } from 'date-fns'; -import { computed, ref } from 'vue'; +import { computed, shallowRef } from 'vue'; import { useRoute } from 'vue-router'; import { defaultSortOrder as sortBy } from '@/utils/items'; import { useDateFns } from '@/composables/use-datefns'; @@ -184,43 +184,52 @@ import { useItemPageTitle } from '@/composables/page-title'; const route = useRoute('/person/[itemId]'); -const activeTab = ref(4); +const activeTab = shallowRef(4); -const { data: item } = await useBaseItem(getUserLibraryApi, 'getItem')(() => ({ - itemId: route.params.itemId -})); -const { data: relatedItems } = await useBaseItem(getLibraryApi, 'getSimilarItems')(() => ({ - itemId: route.params.itemId, - limit: 5 -})); -const { data: movies } = await useBaseItem(getItemsApi, 'getItems')(() => ({ - personIds: [route.params.itemId], - sortBy, - sortOrder: [SortOrder.Descending], - recursive: true, - includeItemTypes: [BaseItemKind.Movie] -})); -const { data: series } = await useBaseItem(getItemsApi, 'getItems')(() => ({ - personIds: [route.params.itemId], - sortBy, - sortOrder: [SortOrder.Descending], - recursive: true, - includeItemTypes: [BaseItemKind.Series] -})); -const { data: books } = await useBaseItem(getItemsApi, 'getItems')(() => ({ - personIds: [route.params.itemId], - sortBy, - sortOrder: [SortOrder.Descending], - recursive: true, - includeItemTypes: [BaseItemKind.Book] -})); -const { data: photos } = await useBaseItem(getItemsApi, 'getItems')(() => ({ - personIds: [route.params.itemId], - sortBy, - sortOrder: [SortOrder.Descending], - recursive: true, - includeItemTypes: [BaseItemKind.Photo] -})); +const [ + { data: item }, + { data: relatedItems }, + { data: movies }, + { data: series }, + { data: books }, + { data: photos } +] = await Promise.all([ + useBaseItem(getUserLibraryApi, 'getItem')(() => ({ + itemId: route.params.itemId + })), + useBaseItem(getLibraryApi, 'getSimilarItems')(() => ({ + itemId: route.params.itemId, + limit: 5 + })), + useBaseItem(getItemsApi, 'getItems')(() => ({ + personIds: [route.params.itemId], + sortBy, + sortOrder: [SortOrder.Descending], + recursive: true, + includeItemTypes: [BaseItemKind.Movie] + })), + useBaseItem(getItemsApi, 'getItems')(() => ({ + personIds: [route.params.itemId], + sortBy, + sortOrder: [SortOrder.Descending], + recursive: true, + includeItemTypes: [BaseItemKind.Series] + })), + useBaseItem(getItemsApi, 'getItems')(() => ({ + personIds: [route.params.itemId], + sortBy, + sortOrder: [SortOrder.Descending], + recursive: true, + includeItemTypes: [BaseItemKind.Book] + })), + useBaseItem(getItemsApi, 'getItems')(() => ({ + personIds: [route.params.itemId], + sortBy, + sortOrder: [SortOrder.Descending], + recursive: true, + includeItemTypes: [BaseItemKind.Photo] + })) +]); const birthDate = computed(() => item.value.PremiereDate diff --git a/frontend/src/pages/search.vue b/frontend/src/pages/search.vue index 2403cae01f9..f8cc7ea6fe8 100644 --- a/frontend/src/pages/search.vue +++ b/frontend/src/pages/search.vue @@ -96,27 +96,28 @@ const searchQuery = computed(() => route.query.q?.toString() ?? ''); const searchDebounced = refDebounced(searchQuery, 400); const itemSearchMethod = computed(() => searchDebounced.value ? 'getItems' : undefined); const peopleSearchMethod = computed(() => searchDebounced.value ? 'getPersons' : undefined); -const { loading: itemLoading, data: itemSearch } = await useBaseItem(getItemsApi, itemSearchMethod, { - skipCache: { request: true } -})(() => ({ - searchTerm: searchDebounced.value, - includeItemTypes: [ - BaseItemKind.Movie, - BaseItemKind.Series, - BaseItemKind.Audio, - BaseItemKind.MusicAlbum, - BaseItemKind.Book, - BaseItemKind.MusicArtist, - BaseItemKind.Person - ], - recursive: true -})); - -const { loading: peopleLoading, data: peopleSearch } = await useBaseItem(getPersonsApi, peopleSearchMethod, { - skipCache: { request: true } -})(() => ({ - searchTerm: searchDebounced.value -})); +const [{ loading: itemLoading, data: itemSearch }, { loading: peopleLoading, data: peopleSearch }] = await Promise.all([ + useBaseItem(getItemsApi, itemSearchMethod, { + skipCache: { request: true } + })(() => ({ + searchTerm: searchDebounced.value, + includeItemTypes: [ + BaseItemKind.Movie, + BaseItemKind.Series, + BaseItemKind.Audio, + BaseItemKind.MusicAlbum, + BaseItemKind.Book, + BaseItemKind.MusicArtist, + BaseItemKind.Person + ], + recursive: true + })), + useBaseItem(getPersonsApi, peopleSearchMethod, { + skipCache: { request: true } + })(() => ({ + searchTerm: searchDebounced.value + })) +]); const serverSearchIds = computed(() => { if (!peopleLoading.value && !itemLoading.value) { diff --git a/frontend/src/pages/series/[itemId].vue b/frontend/src/pages/series/[itemId].vue index e3db3880f0c..32a48a4ea9a 100644 --- a/frontend/src/pages/series/[itemId].vue +++ b/frontend/src/pages/series/[itemId].vue @@ -156,7 +156,8 @@ + :seasons + :season-episodes /> @@ -182,12 +183,15 @@