简体   繁体   中英

dexiejs query get slower overtime

So I am using Svelte+Vite with Dexiejs as my offline Db and Routify for the routes, when I go to a page that is making query to Dexiejs the response is pretty quick on the first request, but when I go to another page and go back to to the same page the response time gets slower each query.

I've used the index like this answer suggest. but it still happens. what did i miss? can anyone recommend any alternatives that have better performance than dexiejs or pouchDB for offline db? I am currently trying pouchDB as alternative

here is my code

let taskDone;
let taskOngoing;
let clustercount;
let tasks = [];
onMount(async function () {
        // @ts-ignore
        let clusterQuery = await db.cluster.reverse().sortBy("id");

        clustercount = clusterQuery.length;

        for (const clusters of clusterQuery) {
            // @ts-ignore
            taskDone = await db.task
                .where("[cluster_id+status]")
                .anyOf([clusters.id, 1], [clusters.id, 2])
                .toArray();

            // @ts-ignore
            taskOngoing = await db.task
                .where({ cluster_id: clusters.id })
                .toArray();

            tasks = [
                {
                    cluster_id: clusters.id,
                    count_done: taskDone.length,
                    count_ongoing: taskOngoing.length,
                    cluster_name: clusters.name,
                },
                ...tasks,
            ];
            count++;
        }
        dispatch("showList", tasks);
    });

It looks like the tasks array is being filled more and more for every time onMount is called. Is it a globally declared variable? Was it meant to be local?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM