The data is charged in 20 seconds and its too much time for a query, how can i impove the code, also when i enter the page1 doestnt run the query.
import {local} from ‘wix-storage’;
import wixData from ‘wix-data’;
import wixLocation from ‘wix-location’;
import wixUsers from ‘wix-users’;
var roleName;
let currentUser = wixUsers.currentUser;
currentUser.getRoles()
.then( (roles) => {
let firstRole = roles[0];
roleName = firstRole.name;
} );
export function searchBox_keyPress() {
search();
}
export function page1_viewportEnter(event) {
search()
}
export function searchButton_click() {
search();
}
export function searchBox_change() {
search();
}
export function dropdown1_change() {
search();
}
export function input1_keyPress() {
search();
}
export function input1_change() {
search();
}
export function resultsTable_rowSelect(event, $w) {
let rowData = event.rowData;
let rowIndex = event.rowIndex;
const myRow = event.target.rows[rowIndex];
wixLocation.to(${myRow["link-invitados-nombre"]}
)
}
function search() {
if (roleName===“Ho”) {
wixData.query(‘invitados’)
.contains(‘dni’, $w(“#searchBox”).value)
.or(wixData.query(‘invitados’).contains(‘nombre’, $w(“#searchBox”).value))
.or(wixData.query(‘invitados’).contains(‘apellido1’, $w(“#searchBox”).value))
.and(wixData.query(‘invitados’).contains(‘evento’,“Ho”))
.find()
.then(res => {
$w(‘#resultsTable’).rows = res.items; // see below
})
}
if (roleName===“Ri”) {
wixData.query(‘invitados’)
.contains(‘dni’, $w(“#searchBox”).value)
.or(wixData.query(‘invitados’).contains(‘nombre’, $w(“#searchBox”).value))
.or(wixData.query(‘invitados’).contains(‘apellido1’, $w(“#searchBox”).value))
.and(wixData.query(‘invitados’).contains(‘evento’,“Ri”))
.find()
.then(res => {
$w(‘#resultsTable’).rows = res.items; // see below
})
}
if (roleName===“Co”) {
wixData.query(‘invitados’)
.contains(‘dni’, $w(“#searchBox”).value)
.or(wixData.query(‘invitados’).contains(‘nombre’, $w(“#searchBox”).value))
.or(wixData.query(‘invitados’).contains(‘apellido1’, $w(“#searchBox”).value))
.and(wixData.query(‘invitados’).contains(‘evento’,“Co”))
.find()
.then(res => {
$w(‘#resultsTable’).rows = res.items; // see below
})
}
if (roleName===“Ki”) {
wixData.query(‘invitados’)
.contains(‘dni’, $w(“#searchBox”).value)
.or(wixData.query(‘invitados’).contains(‘nombre’, $w(“#searchBox”).value))
.or(wixData.query(‘invitados’).contains(‘apellido1’, $w(“#searchBox”).value))
.and(wixData.query(‘invitados’).contains(‘evento’,“Ki”))
.find()
.then(res => {
$w(‘#resultsTable’).rows = res.items; // see below
})
}
if (roleName===“Zo”) {
wixData.query(‘invitados’)
.contains(‘dni’, $w(“#searchBox”).value)
.or(wixData.query(‘invitados’).contains(‘nombre’, $w(“#searchBox”).value))
.or(wixData.query(‘invitados’).contains(‘apellido1’, $w(“#searchBox”).value))
.and(wixData.query(‘invitados’).contains(‘evento’,“Zo”))
.find()
.then(res => {
$w(‘#resultsTable’).rows = res.items; // see below
})
}
if (roleName===“Conc”) {
$w(‘#input1’).show()
wixData.query('invitados')
.contains('dni', $w("#searchBox").value)
.or(wixData.query('invitados').contains('nombre', $w("#searchBox").value))
.or(wixData.query('invitados').contains('apellido1', $w("#searchBox").value))
.and(wixData.query('invitados').contains('evento', $w("#input1").value))
.find()
.then(res => {
$w('#resultsTable').rows = res.items; // see below
})
}
}
$w.onReady(function () {
$w(“#resultsTable”).columns = [
{
“id”: “DNI”,
“dataPath”: “dni”,
“label”: “DNI”,
“width”: 100,
“type”: “text”,
},
{
“id”: “Nombre”, // ID of the column for code purposes
// The field key in the collection whose data this column displays
“dataPath”: “nombre”,
“label”: “Nombre”, // The column header
“width”: 100, // Column width
“type”: “text”, // Data type for the column
},
{
“id”: “Apellido”, // ID of the column for code purposes
// The field key in the collection whose data this column displays
“dataPath”: “apellido1”,
“label”: “Apellido”, // The column header
“width”: 100, // Column width
“type”: “text”, // Data type for the column
},
{
“id”: “Apellido 2”, // ID of the column for code purposes
// The field key in the collection whose data this column displays
“dataPath”: “apellido2”,
“label”: “Apellido 2”, // The column header
“width”: 100, // Column width
“type”: “text”, // Data type for the column
},
{
“id”: “Edad”, // ID of the column for code purposes
// The field key in the collection whose data this column displays
“dataPath”: “fechaNacimiento”,
“label”: “Edad”, // The column header
“width”: 100, // Column width
“type”: “date”, // Data type for the column
},
{
“id”: “Abono”, // ID of the column for code purposes
// The field key in the collection whose data this column displays
“dataPath”: “Abono”,
“label”: “Abono”, // The column header
“width”: 100, // Column width
“type”: “text”, // Data type for the column
},
];
});