once again forgotten observer optimization

feat/vaults
Tomáš Mládek 2021-06-07 01:51:07 +02:00
parent ce60bf5198
commit c4db0b5479
2 changed files with 6 additions and 3 deletions

View File

@ -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<string[]> = computed(() => {
return inferredEntries.value.map((eid) => eid.value);

View File

@ -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<ListingResult, unknown>(
() => `/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<ListingResult, unknown>(() => {
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