From c4db0b5479dc4f2491deabe071011ca2269eb6c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Ml=C3=A1dek?= Date: Mon, 7 Jun 2021 01:51:07 +0200 Subject: [PATCH] once again forgotten observer optimization --- ui/src/components/Address.vue | 2 +- ui/src/lib/entity.ts | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/ui/src/components/Address.vue b/ui/src/components/Address.vue index e97de13..75d2329 100644 --- a/ui/src/components/Address.vue +++ b/ui/src/components/Address.vue @@ -63,7 +63,7 @@ export default defineComponent({ }); // Identification - const { attributes } = useEntity(props.address); + const { attributes } = useEntity(props.address, () => visible.value); const inferredEntries = identify(attributes); const inferredIds: ComputedRef = computed(() => { return inferredEntries.value.map((eid) => eid.value); diff --git a/ui/src/lib/entity.ts b/ui/src/lib/entity.ts index e8cec60..226fce0 100644 --- a/ui/src/lib/entity.ts +++ b/ui/src/lib/entity.ts @@ -4,9 +4,9 @@ import useSWRV from "swrv"; import { computed, ComputedRef, Ref } from "vue"; -export function useEntity(address: string | (() => string)) { +export function useEntity(address: string | (() => string), condition?: () => Boolean) { const { data, error, mutate } = useSWRV( - () => `/api/obj/${typeof address === "string" ? address : address()}`, + () => (condition === undefined || condition()) ? `/api/obj/${typeof address === "string" ? address : address()}` : null, fetcher ); @@ -55,6 +55,7 @@ export function identify(attributes: ComputedRef<[string, IEntry][]>): ComputedR .map(([_, entry]) => entry.value.c); }) + // Out of those, retrieve their TYPE_ID entries const { data: typeIdListing } = useSWRV(() => { return isEntries.value && `/api/obj?query=(matches (in ${isEntries.value.map((e) => `"${e}"`).join(" ")}) "TYPE_ID" ?)`; @@ -66,6 +67,8 @@ export function identify(attributes: ComputedRef<[string, IEntry][]>): ComputedR }); }); + + // Finally, filter own object's attributes according to TYPE_IDs return computed(() => { // For each identity/TYPE_ID pair