Much better searching triggers for recovery meetings (events).
This commit is contained in:
@@ -106,6 +106,139 @@ $: if ($idaa_trig.event_li) {
|
||||
log_lvl: log_lvl,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
$: if ($idaa_trig.event_li_qry) {
|
||||
$idaa_trig.event_li_qry = false;
|
||||
|
||||
if (log_lvl) {
|
||||
console.log(`Triggered: $idaa_trig.event_li_qry`);
|
||||
}
|
||||
|
||||
let and_physical = $idaa_loc.recovery_meetings.qry__physical;
|
||||
let and_virtual = $idaa_loc.recovery_meetings.qry__virtual;
|
||||
let and_type = $idaa_loc.recovery_meetings.qry__type;
|
||||
let order_by_li = $idaa_loc.recovery_meetings.qry__order_by_li;
|
||||
let search_delay = 15;
|
||||
let max_tries = 5;
|
||||
let try_cache = true;
|
||||
|
||||
let params = {
|
||||
'qry__enabled': $idaa_loc.recovery_meetings.qry__enabled ?? 'enabled',
|
||||
'qry__hidden': $idaa_loc.recovery_meetings.qry__hidden ?? 'not_hidden',
|
||||
'qry__limit': $idaa_loc.recovery_meetings.qry__limit ?? 35,
|
||||
};
|
||||
|
||||
|
||||
if ($idaa_loc.recovery_meetings.qry__enabled !== 'all' || $idaa_loc.recovery_meetings.qry__hidden !== 'all') {
|
||||
console.log(`Deleting disabled or hidden event.`);
|
||||
let results = db_events.events
|
||||
.clear();
|
||||
console.log(`Deleted ${results} disabled event.`);
|
||||
|
||||
}
|
||||
|
||||
if ($idaa_sess.recovery_meetings?.qry__status != null && $idaa_sess.recovery_meetings?.qry__status != 'done') {
|
||||
console.log('*** TEST SEARCH - $idaa_sess.recovery_meetings.qry__status != done ***');
|
||||
// WARNING: This is a temporary fix for the search string. It needs to be fixed in the future. Using lk_search_str for now.
|
||||
$idaa_sess.recovery_meetings.status_qry__last_request_str = $idaa_loc.recovery_meetings.qry__fulltext_str;
|
||||
|
||||
// We want to delay the initial search request to give the previous search request to finish.
|
||||
let random_delay = Math.floor(Math.random() * 50);
|
||||
search_delay += 50+random_delay;
|
||||
}
|
||||
|
||||
log_lvl = 1;
|
||||
|
||||
let count = 0;
|
||||
let request_loop = setInterval(() => {
|
||||
count++;
|
||||
if (log_lvl) {
|
||||
console.log(`*** TEST SEARCH - Search delay: ${search_delay} *** loop count=${count}`);
|
||||
}
|
||||
if (count >= max_tries) {
|
||||
console.log('*** TEST SEARCH - Max tries reached ***');
|
||||
clearInterval(request_loop);
|
||||
}
|
||||
|
||||
if ($idaa_sess.recovery_meetings?.qry__status != null && $idaa_sess.recovery_meetings?.qry__status != 'done') {
|
||||
let random_delay = Math.floor(Math.random() * 25);
|
||||
search_delay += 25+random_delay;
|
||||
console.log(`*** TEST SEARCH - $idaa_sess.recovery_meetings.qry__status == loading wait *** search_delay=${search_delay}`);
|
||||
// $idaa_sess.status_qry__last_request_str = $idaa_loc.recovery_meetings.qry__fulltext_str;
|
||||
} else {
|
||||
console.log('*** TEST SEARCH - $idaa_sess.recovery_meetings.qry__status != loading ***');
|
||||
|
||||
$idaa_sess.recovery_meetings.qry__status = 'loading';
|
||||
|
||||
(and_physical) ?? null;
|
||||
(and_virtual) ?? null;
|
||||
(and_type) ?? null;
|
||||
// if (and_type) and_type = and_type;
|
||||
// if (!and_type) {
|
||||
// and_type = null;
|
||||
// }
|
||||
|
||||
console.log(`TEST - and_physical: ${and_physical}; and_virtual: ${and_virtual}; and_type: ${and_type}; qry__fulltext_str: ${$idaa_loc.recovery_meetings.qry__fulltext_str}; params:`, params);
|
||||
|
||||
$idaa_prom.load__event_obj_qry = events_func.qry_ae_obj_li__event({
|
||||
api_cfg: $ae_api,
|
||||
for_obj_type: 'account',
|
||||
for_obj_id: $ae_loc.account_id,
|
||||
order_by_li: order_by_li,
|
||||
qry_conference: false,
|
||||
qry_physical: and_physical,
|
||||
qry_virtual: and_virtual,
|
||||
qry_type: and_type,
|
||||
qry_str: $idaa_loc.recovery_meetings.qry__fulltext_str,
|
||||
params: params,
|
||||
try_cache: try_cache,
|
||||
log_lvl: log_lvl,
|
||||
})
|
||||
.then(function (search_results) {
|
||||
// Processing the results from the search.
|
||||
$idaa_sess.recovery_meetings.qry__status = 'processing';
|
||||
$idaa_slct.event_obj_li = search_results;
|
||||
console.log(search_results);
|
||||
// $idaa_sess.recovery_meetings.qry__status = 'done';
|
||||
|
||||
if (log_lvl) {
|
||||
console.log('TEST SEARCH - Search done. Pulling out the event_id_randoms.');
|
||||
}
|
||||
// console.log(`TEST search: ${$lq_kv__event_obj_li}`);
|
||||
|
||||
// event_id_random_li = [];
|
||||
|
||||
// We need to loop through the array of objects and get the event_id_random from each object a new list of event_id_randoms. Then we can use this list to get the full objects from the database.
|
||||
let tmp_li = []; // This is to prevent the array from constantly updating and triggering the liveQuery.
|
||||
if (search_results && search_results.length) {
|
||||
for (let i = 0; i < search_results.length; i++) {
|
||||
tmp_li.push($idaa_slct.event_obj_li[i].event_id_random);
|
||||
}
|
||||
}
|
||||
event_id_random_li = tmp_li;
|
||||
})
|
||||
.finally(() => {
|
||||
|
||||
|
||||
// event_id_random_li = $idaa_slct.event_obj_li.map(session_obj => session_obj.event_id_random);
|
||||
|
||||
// Finally done with the search.
|
||||
$idaa_sess.recovery_meetings.qry__status = 'done';
|
||||
|
||||
if (log_lvl > 1) {
|
||||
console.log(`TEST SEARCH - event_id_random_li:`, event_id_random_li);
|
||||
// console.log(`TEST SEARCH - search live query: ${$lq_kv__event_obj_li}`);
|
||||
}
|
||||
|
||||
});
|
||||
clearInterval(request_loop);
|
||||
}
|
||||
}, search_delay);
|
||||
|
||||
}
|
||||
|
||||
|
||||
</script>
|
||||
|
||||
<!-- ({$lq__event_obj?.event_id ?? ''}) -->
|
||||
|
||||
Reference in New Issue
Block a user