瀏覽代碼

Revert "test cache cleaning on notifications fetching"

This reverts commit ae4583cc2b35895c3d439adcac12f87b5a9c59f7.
Olivier Massot 2 年之前
父節點
當前提交
f591064db2
共有 2 個文件被更改,包括 11 次插入17 次删除
  1. 4 5
      components/Layout/Header/Notification.vue
  2. 7 12
      composables/data/useEntityFetch.ts

+ 4 - 5
components/Layout/Header/Notification.vue

@@ -17,12 +17,11 @@
     </v-badge>
   </v-btn>
 
-  <v-tooltip v-if="btn !== null" :activator="btn" location="bottom">
+  <v-tooltip :activator="btn" location="bottom">
     <span>{{ $t('notification') }}</span>
   </v-tooltip>
 
   <v-menu
-      v-if="btn !== null"
       :activator="btn"
       v-model="isOpen"
       location="bottom left"
@@ -123,8 +122,8 @@ const query: ComputedRef<AnyJson> = computed(() => {
   return { 'page': page.value }
 })
 
-clearNuxtData('notifications')
-let { data: collection, pending, refresh } = await fetchCollection(Notification, null, query, 'notifications')
+
+let { data: collection, pending, refresh } = await fetchCollection(Notification, null, query)
 
 /**
  * On récupère les Notifications via le store (sans ça, les mises à jour SSE ne seront pas prises en compte)
@@ -144,7 +143,7 @@ const unreadNotification: ComputedRef<Array<Notification>> = computed(() => {
  * Les metadata dépendront de la dernière valeur du GET lancé
  */
 const pagination: ComputedRef<Pagination> = computed(() => {
-  return !pending.value ? collection.value.pagination : {}
+  return collection.value !== null ? collection.value.pagination : {}
 })
 
 const notificationUrl = UrlUtils.join(runtimeConfig.baseUrlAdminLegacy, 'notifications/list/')

+ 7 - 12
composables/data/useEntityFetch.ts

@@ -3,32 +3,27 @@ import ApiResource from "~/models/ApiResource";
 import {AssociativeArray, Collection} from "~/types/data";
 import {AsyncData} from "#app";
 import {ComputedRef, Ref} from "vue";
-import {v4 as uuid4} from "uuid";
 
 interface useEntityFetchReturnType {
-    fetch: (model: typeof ApiResource, id: number, key?: string | null) => AsyncData<ApiResource, ApiResource | true>,
-    fetchCollection: (model: typeof ApiResource, parent?: ApiResource | null, query?: Ref<AssociativeArray>, key?: string | null) => AsyncData<Collection, any>
+    fetch: (model: typeof ApiResource, id: number) => AsyncData<ApiResource, ApiResource | true>,
+    fetchCollection: (model: typeof ApiResource, parent?: ApiResource | null, query?: Ref<AssociativeArray>) => AsyncData<Collection, any>
     // @ts-ignore
     getRef: <T extends ApiResource>(model: typeof T, id: Ref<number | null>) => ComputedRef<null | T>
 }
 
+
 // TODO: améliorer le typage des fonctions sur le modèle de getRef
 export const useEntityFetch = (lazy: boolean = false): useEntityFetchReturnType => {
     const { em } = useEntityManager()
 
-    const fetch = (model: typeof ApiResource, id: number, key: string | null = null) => useAsyncData(
-        key ?? (model.entity + '_' + id + '_' + uuid4()),
+    const fetch = (model: typeof ApiResource, id: number) => useAsyncData(
+        model.entity + '_' + id,
         () => em.fetch(model, id, true),
         { lazy }
     )
 
-    const fetchCollection = (
-        model: typeof ApiResource,
-        parent: ApiResource | null = null,
-        query: Ref<AssociativeArray | null> = ref(null),
-        key: string | null = null
-    ) => useAsyncData(
-        key ?? (model.entity + '_many_' + uuid4()),
+    const fetchCollection = (model: typeof ApiResource, parent: ApiResource | null = null, query: Ref<AssociativeArray> = ref([])) => useAsyncData(
+        model.entity + '_many',
         () => em.fetchCollection(model, parent, query.value),
         { lazy }
     )