Skip to content

Openverse is a search engine for openly-licensed media. This monorepo includes all application code.

Stop fetching the media twice in the search page (#1422)

Krystle Salazard8f63c044479
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index c0392a98b..217259c89 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -121,7 +121,7 @@ jobs:
playwright-test-failure-comment:
name: Share Playwright test debugging instructions
runs-on: ubuntu-latest
- if: ${{ always() }}
+ if: always() && (needs.nuxt-playwright.result == 'failure' || needs.storybook-playwright.result == 'failure')
needs:
- nuxt-playwright
- storybook-playwright
diff --git a/src/pages/index.vue b/src/pages/index.vue
index f4125c047..fbfd9296e 100644
--- a/src/pages/index.vue
+++ b/src/pages/index.vue
@@ -226,8 +226,6 @@ const HomePage = {
query,
})
router.push(newPath)
-
- await mediaStore.fetchMedia()
}
return {
diff --git a/src/pages/search.vue b/src/pages/search.vue
index 5dfa822c3..e437e3089 100644
--- a/src/pages/search.vue
+++ b/src/pages/search.vue
@@ -8,7 +8,7 @@
:query="query"
:supported="supported"
:search-type="searchType"
- :results-count="resultsCount"
+ :results-count="resultCount"
data-testid="search-grid"
@tab="handleTab($event, 'search-grid')"
>
@@ -36,7 +36,6 @@
import { isShallowEqualObjects } from '@wordpress/is-shallow-equal'
import { computed, defineComponent, inject, ref } from '@nuxtjs/composition-api'
-import { supportedSearchTypes } from '~/constants/media'
import { isMinScreen } from '~/composables/use-media-query'
import { useFilterSidebarVisibility } from '~/composables/use-filter-sidebar-visibility'
import { Focus, focusIn } from '~/utils/focus-management'
@@ -66,9 +65,7 @@ export default defineComponent({
const searchTerm = computed(() => searchStore.searchTerm)
const searchType = computed(() => searchStore.searchType)
const query = computed(() => searchStore.searchQueryParams)
- const supported = computed(() =>
- supportedSearchTypes.includes(searchType.value)
- )
+ const supported = computed(() => searchStore.searchTypeIsSupported)
const resultCount = computed(() => mediaStore.resultCount)
const fetchState = computed(() => mediaStore.fetchState)
const resultItems = computed(() => mediaStore.resultItems)
@@ -97,27 +94,21 @@ export default defineComponent({
handleTab,
}
},
- asyncData({ route, $pinia }) {
+ async asyncData({ route, $pinia }) {
const searchStore = useSearchStore($pinia)
+ const mediaStore = useMediaStore($pinia)
searchStore.setSearchStateFromUrl({
path: route.path,
urlQuery: route.query,
})
- },
- async fetch() {
- if (this.supported && !this.resultCount && this.searchTerm.trim() !== '') {
- await this.fetchMedia()
+ if (
+ searchStore.searchTypeIsSupported &&
+ !mediaStore.resultCount &&
+ searchStore.searchTerm.trim() !== ''
+ ) {
+ await mediaStore.fetchMedia()
}
},
- computed: {
- /**
- * Number of search results. Returns 0 for unsupported types.
- * @returns {number}
- */
- resultsCount() {
- return this.supported ? this.resultCount : 0 ?? 0
- },
- },
watch: {
/**
* Updates the search type only if the route's path changes.
diff --git a/src/stores/search.ts b/src/stores/search.ts
index 4f10681e2..ca77c6100 100644
--- a/src/stores/search.ts
+++ b/src/stores/search.ts
@@ -113,6 +113,12 @@ export const useSearchStore = defineStore('search', {
filterKey !== 'mature' && filterItems.some((filter) => filter.checked)
)
},
+ /**
+ * Returns whether the current `seartchType` is a supported media type for search.
+ */
+ searchTypeIsSupported(state) {
+ return supportedSearchTypes.includes(state.searchType)
+ },
},
actions: {
setSearchType(type: SupportedSearchType) {