Querying a wix database with 150 000+ records. Even when setting .limit(1000) or .limit(100) I am getting a “WDE0028: Request timed out.” error
This is happening in both backend and front end code
Any advice?
Backend Code triggered by a button OnClick event:
import wixData from 'wix-data';
export function queryViews() {
return wixData.query("Activity")
.contains("AdClickOwner", "Viewed Page:")
.limit(1000)
.find()
.then((results) => {
console.log("query complete");
if (results.items.length > 0) {
let items = results.items;
let firstItem = items[0];
console.log(firstItem);
} else {
console.log("no matching items")
}
})
.catch((error) => {
let errorMsg = error.message;
let code = error.code;
console.log(errorMsg);
console.log(code);
});
}
Hi there …
The code itself is fine, the WDE0028 error might occur due to wide variety of reasons including an ISP delay, please try publishing your site and try again, if that still doesn’t solve the problem try using a VPN temprarily, whatever the result was, please report it to Wix support and provide them with your ISP name and country.
Side note: You’re not returning anything from the query, the time out might also occur due to this reason as well.
I’m not quite sure how that has anything to do with it. When I alternate to a different ISP I still get the error
Updated the code to retry after timeout, still getting this error. Bit of a problem as I cannot query my principal DB…
import wixData from 'wix-data';
export function queryViews() {
let query = wixData.query("Activity")
.contains("AdClickOwner", "Viewed Page:")
.limit(100)
return retryQuery(query)
.then((results) => {
console.log("query complete");
if (results.items.length > 0) {
let items = results.items;
let firstItem = items[0];
console.log(firstItem);
return firstItem;
} else {
console.log("no matching items")
}
})
.catch((error) => {
let errorMsg = error.message;
let code = error.code;
console.log(errorMsg);
console.log(code);
});
}
const TIMEOUT_CODE_ONE = 'WDE0028: Request timed out.'; // error message from wix server
const TIMEOUT_CODE_TWO = 'WD_REQUEST_TIMED_OUT'; // error message from wix server
const RETRY_MAX = 3;
function retryQuery(query, iteration = 0) {
return query.find()
.catch(reason => {
if (reason === TIMEOUT_CODE_ONE || reason === TIMEOUT_CODE_TWO) {
if (iteration === RETRY_MAX) {
console.log("retrying");
console.error('retried ' + RETRY_MAX + ' times and failed');
throw reason;
}
return retryQuery(query, ++iteration);
}
//Not a timeout, throw back the error
throw reason;
})
}