bugfix: improve filter performances
What has been done here:
- put all the search logic in an external file
- use
Promise.all
instead of allreduce
to parallelize the search per resource - cache some tests which were done too many times (is this filter a set, or a custom search field)
- throw errors and catch them instead of waiting the
Promise.all
to return when it's not necessary
Estimated gain: ~ x8 for the following example (5-7s before / 600-800ms now)
Test example
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<script type="module" src="/lib/sib-core/dist/index.js"></script>
<script type="module" src="https://unpkg.com/@startinblox/oidc@latest"></script>
</head>
<body>
<sib-auth auto-login
><sib-auth-provider
data-authority="https://api.energie-partagee-dev.startinblox.com"
data-id="dataserver"
data-client-name="Sample of a functional Orbit"
></sib-auth-provider>
</sib-auth>
<div class="row">
<solid-form-search
id="dashboard-filter"
fields="actor.longname, year, filterwindow(actor.region, amount, paymentmethod, receivedby, contributionstatus, integration(actor.integrationstep.packagestep,actor.integrationstep.adhspacestep, actor.integrationstep.adhliststep, actor.integrationstep.regionalliststep), actor.actortype)"
widget-year="solid-form-number"
widget-actor.longname="solid-form-text-placeholder"
widget-actor.region="solid-form-checkboxes-label"
range-actor.region="https://api.energie-partagee-dev.startinblox.com/regions/"
order-asc-actor.region="name"
widget-amount="solid-form-rangenumber-label"
range-paymentmethod="https://api.energie-partagee-dev.startinblox.com/paymentmethods/"
widget-paymentmethod="solid-form-dropdown-label"
range-receivedby="https://api.energie-partagee-dev.startinblox.com/regionalnetworks/"
widget-receivedby="solid-form-dropdown-label"
enum-contributionstatus="Appel à envoyer = appel_a_envoye, Appel envoyé = ok, Relancé = relance, À ventiler = a_ventiler, Validé = valide"
widget-contributionstatus="solid-form-dropdown-label"
widget-actor.integrationstep.packagestep="solid-form-checkbox"
widget-actor.integrationstep.adhspacestep="solid-form-checkbox"
widget-actor.integrationstep.adhliststep="solid-form-checkbox"
widget-actor.integrationstep.regionalliststep="solid-form-checkbox"
enum-actor.actortype="Société Citoyenne = soc_citoy, Structures d’Accompagnement = structure, Collectivité = collectivite, Partenaire = partenaire"
widget-actor.actortype="solid-form-dropdown-label"
></solid-form-search>
<solid-table
id="actors-table"
fields="@id"
filtered-by="dashboard-filter"
paginate-by="30"
></solid-table>
</div>
<style>
.row {
display: flex;
}
</style>
<script>
document.addEventListener("DOMContentLoaded", () => {
const actorsTable = document.getElementById("actors-table");
Promise.all([
window.sibStore.getData(
"https://api.energie-partagee-dev.startinblox.com/regionalnetworks/",
actorsTable.component.context
),
window.sibStore.getData(
"https://api.energie-partagee-dev.startinblox.com/regions/",
actorsTable.component.context
),
window.sibStore.getData(
"https://api.energie-partagee-dev.startinblox.com/paymentmethods/",
actorsTable.component.context
),
window.sibStore.getData(
"https://api.energie-partagee-dev.startinblox.com/users/",
actorsTable.component.context
),
window.sibStore.getData(
"https://api.energie-partagee-dev.startinblox.com/actors/",
actorsTable.component.context
),
window.sibStore.getData(
"https://api.energie-partagee-dev.startinblox.com/integrationsteps/",
actorsTable.component.context
)
]).then(() => {
actorsTable.setAttribute(
"data-src",
"https://api.energie-partagee-dev.startinblox.com/contributions/"
);
});
});
</script>
</body>
</html>