fix: refactor code as suggested for performance

This commit is contained in:
mariodz95 2025-07-21 16:51:40 +02:00
commit e16b5136ac
2 changed files with 3 additions and 8 deletions

View file

@ -414,15 +414,8 @@ export default defineNuxtComponent({
loading.value = false;
}
const seededQuery = computed(() => {
return {
...props.query,
_searchSeed: Date.now().toString(),
};
});
async function navigateRandom() {
const recipe = await getRandom(seededQuery.value, queryFilter.value);
const recipe = await getRandom(props.query, queryFilter.value);
if (!recipe?.slug) {
return;
}

View file

@ -90,6 +90,8 @@ export const useLazyRecipes = function (publicGroupSlug: string | null = null) {
}
async function getRandom(query: RecipeSearchQuery | null = null, queryFilter: string | null = null) {
query = query || {};
query._searchSeed = query._searchSeed || Date.now().toString();
const { data } = await api.recipes.getAll(1, 1, getParams("random", "desc", null, query, queryFilter));
if (data?.items.length) {
return data.items[0];