The search is working better now. Also better and less debug logging.
This commit is contained in:
@@ -101,7 +101,7 @@ export let get_object = async function get_object(
|
||||
console.log('URL params:');
|
||||
}
|
||||
for (const prop in params) {
|
||||
if (log_lvl) {
|
||||
if (log_lvl > 1) {
|
||||
console.log(`URL param: ${prop}: ${params[prop]}`);
|
||||
}
|
||||
if (params[prop] === null ) {
|
||||
@@ -119,7 +119,7 @@ export let get_object = async function get_object(
|
||||
let percent_completed = Math.round(
|
||||
(progressEvent.loaded * 100) / progressEvent.total
|
||||
);
|
||||
if (log_lvl) {
|
||||
if (log_lvl > 1) {
|
||||
console.log('GET Data Progress:', progressEvent.progress, 'Total:', progressEvent.total, 'Loaded:', progressEvent.loaded, 'Percent Completed', percent_completed);
|
||||
}
|
||||
|
||||
@@ -206,6 +206,20 @@ export let get_object = async function get_object(
|
||||
}
|
||||
})
|
||||
.catch(function (error) {
|
||||
// Handle the common and expected 404 "error" first
|
||||
if (error.response && error.response.status === 404) {
|
||||
if (log_lvl) {
|
||||
console.log('The response was a 404 not found "error". Returning null.');
|
||||
}
|
||||
if (log_lvl > 1) {
|
||||
console.log(error.response);
|
||||
}
|
||||
if (log_lvl > 2) {
|
||||
console.log(error);
|
||||
}
|
||||
return null; // Returning null since there were no results
|
||||
}
|
||||
|
||||
if (log_lvl) {
|
||||
console.log(`Base URL: ${api_cfg['base_url']} | Endpoint: ${endpoint}`);
|
||||
console.log('Error Message:', error.message); // Is this needed here or below in the in the else portion???
|
||||
@@ -230,18 +244,6 @@ export let get_object = async function get_object(
|
||||
console.log(error.config);
|
||||
}
|
||||
|
||||
if (error.response && error.response.status === 404) {
|
||||
if (log_lvl) {
|
||||
console.log('The response was a 404 not found "error". Returning null.');
|
||||
}
|
||||
if (log_lvl > 1) {
|
||||
console.log(error.response);
|
||||
}
|
||||
if (log_lvl > 2) {
|
||||
console.log(error);
|
||||
}
|
||||
return null; // Returning null since there were no results
|
||||
}
|
||||
if (error.code === 'ECONNABORTED') {
|
||||
// Timeout Error (You can implement retry here where suitable)
|
||||
console.log('Timeout Error: ', error.message);
|
||||
@@ -265,7 +267,9 @@ export let get_object = async function get_object(
|
||||
return response_data_promise;
|
||||
} else if (response_data_promise === null) {
|
||||
// Less common, but expected response if no results were returned.
|
||||
console.log('Returning null. This is expected if no results were found.');
|
||||
if (log_lvl) {
|
||||
console.log('Returning null. This is expected if no results were found.');
|
||||
}
|
||||
return response_data_promise;
|
||||
} else if (response_data_promise === false) {
|
||||
// Not common, but expected response if the request to the API had an issue.
|
||||
|
||||
@@ -81,6 +81,7 @@ export async function load_ae_obj_li__event(
|
||||
inc_presenter_li = false,
|
||||
inc_session_li = false,
|
||||
order_by_li = {'start_datetime': 'DESC', 'name': 'ASC', 'updated_on': 'DESC', 'created_on': 'DESC'},
|
||||
params_json = null,
|
||||
params = {},
|
||||
try_cache = true,
|
||||
log_lvl = 0
|
||||
@@ -96,6 +97,7 @@ export async function load_ae_obj_li__event(
|
||||
inc_presenter_li?: boolean,
|
||||
inc_session_li?: boolean,
|
||||
order_by_li?: key_val,
|
||||
params_json?: null|key_val,
|
||||
params?: key_val,
|
||||
try_cache?: boolean,
|
||||
log_lvl?: number
|
||||
@@ -108,19 +110,31 @@ export async function load_ae_obj_li__event(
|
||||
let limit: number = (params.qry__limit ?? 99); // 99
|
||||
let offset: number = (params.qry__offset ?? 0); // 0
|
||||
|
||||
|
||||
let params_json: key_val = {};
|
||||
|
||||
params_json['and_qry'] = {};
|
||||
// There is probably a better way to handle this. I don't want to just start a new object if it is not passed. However, the qry_conference and qry_str are sort of a special case. -2024-10-01
|
||||
if (!params_json) {
|
||||
params_json = {};
|
||||
}
|
||||
|
||||
if (qry_conference) {
|
||||
if (!params_json['and_qry']) {
|
||||
params_json['and_qry'] = {};
|
||||
}
|
||||
|
||||
params_json['and_qry']['conference'] = qry_conference;
|
||||
} else if (qry_conference === false) {
|
||||
if (!params_json['and_qry']) {
|
||||
params_json['and_qry'] = {};
|
||||
}
|
||||
|
||||
console.log('qry_conference is false!');
|
||||
params_json['and_qry']['conference'] = qry_conference;
|
||||
}
|
||||
|
||||
if (qry_str) {
|
||||
if (!params_json['ft_qry']) {
|
||||
params_json['ft_qry'] = {};
|
||||
}
|
||||
|
||||
params_json['ft_qry'] = {};
|
||||
params_json['ft_qry']['default_qry_str'] = qry_str;
|
||||
params_json['ft_qry']['location_address_json_ext'] = qry_str;
|
||||
@@ -191,8 +205,8 @@ export async function qry_ae_obj_li__event(
|
||||
for_obj_type = 'account',
|
||||
for_obj_id,
|
||||
qry_conference = true,
|
||||
qry_virtual = null,
|
||||
qry_physical = null,
|
||||
qry_virtual = null,
|
||||
qry_type = null,
|
||||
qry_str = null,
|
||||
inc_file_li = false,
|
||||
@@ -209,8 +223,8 @@ export async function qry_ae_obj_li__event(
|
||||
for_obj_type: string,
|
||||
for_obj_id: string,
|
||||
qry_conference?: null|boolean,
|
||||
qry_virtual?: null|boolean,
|
||||
qry_physical?: null|boolean,
|
||||
qry_virtual?: null|boolean,
|
||||
qry_type?: null|string,
|
||||
qry_str?: null|string,
|
||||
inc_file_li?: boolean,
|
||||
@@ -231,29 +245,28 @@ export async function qry_ae_obj_li__event(
|
||||
let limit: number = (params.qry__limit ?? 99); // 99
|
||||
let offset: number = (params.qry__offset ?? 0); // 0
|
||||
|
||||
// Build the params_json object. This needs to be documented better! -2024-10-01
|
||||
let params_json: key_val = {};
|
||||
|
||||
params_json['and_qry'] = {};
|
||||
|
||||
if (qry_conference) {
|
||||
params_json['and_qry']['conference'] = qry_conference;
|
||||
} else if (qry_conference === false) {
|
||||
console.log('qry_conference is false!');
|
||||
params_json['and_qry']['conference'] = qry_conference;
|
||||
}
|
||||
// This is handled in the actual load_ae_obj_li__event() function. For now...?
|
||||
// if (qry_conference) {
|
||||
// params_json['and_qry']['conference'] = qry_conference;
|
||||
// } else if (qry_conference === false) {
|
||||
// console.log('qry_conference is false!');
|
||||
// params_json['and_qry']['conference'] = qry_conference;
|
||||
// }
|
||||
|
||||
if (qry_virtual) {
|
||||
params_json['and_qry']['virtual'] = qry_virtual;
|
||||
} else if (qry_virtual === false) {
|
||||
console.log('qry_virtual is false!');
|
||||
params_json['and_qry']['virtual'] = qry_virtual;
|
||||
}
|
||||
|
||||
if (qry_physical) {
|
||||
params_json['and_qry']['physical'] = qry_physical;
|
||||
} else if (qry_physical === false) {
|
||||
console.log('qry_physical is false!');
|
||||
params_json['and_qry']['physical'] = qry_physical;
|
||||
if (qry_physical && qry_virtual) {
|
||||
// Ignore both if both are set to true.
|
||||
} else if (qry_physical || qry_virtual) {
|
||||
if (qry_physical) {
|
||||
params_json['and_qry']['physical'] = qry_physical;
|
||||
}
|
||||
if (qry_virtual) {
|
||||
params_json['and_qry']['virtual'] = qry_virtual;
|
||||
}
|
||||
}
|
||||
|
||||
if (qry_type) {
|
||||
@@ -283,6 +296,7 @@ export async function qry_ae_obj_li__event(
|
||||
inc_presenter_li: inc_presenter_li,
|
||||
inc_session_li: inc_session_li,
|
||||
order_by_li: order_by_li,
|
||||
params_json: params_json,
|
||||
params: params,
|
||||
try_cache: try_cache,
|
||||
log_lvl: log_lvl
|
||||
|
||||
@@ -73,6 +73,7 @@ import {
|
||||
let export_obj = {
|
||||
handle_load_ae_obj_id__event: events.load_ae_obj_id__event,
|
||||
load_ae_obj_li__event: events.load_ae_obj_li__event,
|
||||
qry_ae_obj_li__event: events.qry_ae_obj_li__event,
|
||||
create_ae_obj__event: events.create_ae_obj__event,
|
||||
update_ae_obj__event: events.update_ae_obj__event,
|
||||
handle_db_save_ae_obj_li__event: events.db_save_ae_obj_li__event,
|
||||
|
||||
@@ -54,7 +54,8 @@ $: lq_new__event_obj_li = liveQuery(async () => {
|
||||
let link_to_id: string = $slct.account_id;
|
||||
console.log(`link_to_type: ${link_to_type}; link_to_id: ${link_to_id}`);
|
||||
|
||||
if (event_id_random_li?.length) {
|
||||
// Check if event_id_random_li is an array and not undefined
|
||||
if (event_id_random_li) {
|
||||
console.log(`Trying bulkGet:`, event_id_random_li);
|
||||
let results = await db_events.events
|
||||
.bulkGet(event_id_random_li);
|
||||
|
||||
@@ -40,20 +40,21 @@ $: if (ae_trigger == 'load__event_obj_li') {
|
||||
setTimeout(() => {
|
||||
console.log("Delayed for X second.");
|
||||
// ae_trigger = null;
|
||||
handle_search__event({lk_search_str: $idaa_loc.recovery_meetings.qry__fulltext_str});
|
||||
handle_qry__event({ft_qry_str: $idaa_loc.recovery_meetings.qry__fulltext_str});
|
||||
}, 250);
|
||||
} else {
|
||||
console.log('*** $idaa_sess.recovery_meetings.qry_status != loading ***');
|
||||
// ae_trigger = null;
|
||||
handle_search__event({lk_search_str: $idaa_loc.recovery_meetings.qry__fulltext_str});
|
||||
handle_qry__event({ft_qry_str: $idaa_loc.recovery_meetings.qry__fulltext_str});
|
||||
}
|
||||
}
|
||||
|
||||
async function handle_search__event(
|
||||
async function handle_qry__event(
|
||||
{
|
||||
ft_search_str = '',
|
||||
lk_search_str = '',
|
||||
and_lk_location_name = '',
|
||||
ft_qry_str = '',
|
||||
and_physical = $idaa_loc.recovery_meetings.qry__physical,
|
||||
and_virtual = $idaa_loc.recovery_meetings.qry__virtual,
|
||||
and_type = $idaa_loc.recovery_meetings.qry__type,
|
||||
search_delay = 0,
|
||||
max_tries = 5,
|
||||
params = {
|
||||
@@ -61,12 +62,13 @@ async function handle_search__event(
|
||||
'qry__hidden': $idaa_loc.recovery_meetings.qry__hidden ?? 'not_hidden',
|
||||
'qry__limit': $idaa_loc.recovery_meetings.qry__limit ?? 35,
|
||||
},
|
||||
try_cache=false,
|
||||
log_lvl=1,
|
||||
try_cache = false,
|
||||
log_lvl = 1,
|
||||
}: {
|
||||
ft_search_str?: string,
|
||||
lk_search_str?: string,
|
||||
and_lk_location_name?: string,
|
||||
ft_qry_str?: string,
|
||||
and_physical?: null|boolean,
|
||||
and_virtual?: null|boolean,
|
||||
and_type?: null|string,
|
||||
search_delay?: number, // In milliseconds
|
||||
max_tries?: number,
|
||||
params?: key_val,
|
||||
@@ -74,19 +76,19 @@ async function handle_search__event(
|
||||
log_lvl?: number,
|
||||
}
|
||||
) {
|
||||
console.log('handle_search__event()');
|
||||
console.log('handle_qry__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 = lk_search_str;
|
||||
$idaa_sess.recovery_meetings.status_qry__last_request_str = ft_qry_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 = 2;
|
||||
log_lvl = 1;
|
||||
|
||||
let count = 0;
|
||||
let request_loop = setInterval(() => {
|
||||
@@ -103,30 +105,35 @@ async function handle_search__event(
|
||||
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 = lk_search_str;
|
||||
// $idaa_sess.status_qry__last_request_str = ft_qry_str;
|
||||
} else {
|
||||
console.log('*** TEST SEARCH - $idaa_sess.recovery_meetings.qry__status != loading ***');
|
||||
|
||||
$idaa_sess.recovery_meetings.qry__status = 'loading';
|
||||
|
||||
search_submit_results = events_func.load_ae_obj_li__event({
|
||||
(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}; ft_qry_str: ${ft_qry_str}; params:`, params);
|
||||
|
||||
search_submit_results = 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: {'priority': 'DESC', 'sort': 'DESC', 'updated_on': 'DESC', 'created_on': 'DESC', 'name': 'ASC'},
|
||||
qry_conference: false,
|
||||
qry_str: lk_search_str,
|
||||
// type_code: type_code,
|
||||
// qry__fulltext_str: ft_search_str,
|
||||
// ft_presenter_search_qry_str: null,
|
||||
// like_search_qry_str: lk_search_str,
|
||||
// like_presentation_search_qry_str: lk_search_str,
|
||||
// like_presenter_search_qry_str: lk_search_str,
|
||||
// external_event_id: $idaa_loc.recovery_meetings.default__external_registration_id,
|
||||
// location_name: and_lk_location_name,
|
||||
qry_physical: and_physical,
|
||||
qry_virtual: and_virtual,
|
||||
qry_type: and_type,
|
||||
qry_str: ft_qry_str,
|
||||
params: params,
|
||||
try_cache: try_cache,
|
||||
log_lvl: 0,
|
||||
log_lvl: log_lvl,
|
||||
})
|
||||
.then(function (search_results) {
|
||||
// Processing the results from the search.
|
||||
|
||||
Reference in New Issue
Block a user