More updates to start using the newer/better way of saving to IDB.
This commit is contained in:
@@ -8,7 +8,7 @@ export let patch_object = async function patch_object(
|
||||
params = {},
|
||||
data = {},
|
||||
return_meta = false,
|
||||
log_lvl = 1,
|
||||
log_lvl = 0,
|
||||
retry_count = 5 // Number of retry attempts
|
||||
}: {
|
||||
api_cfg: any,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import type { key_val } from '$lib/ae_stores';
|
||||
import { api } from '$lib/api';
|
||||
|
||||
import { db_save_ae_obj_li__ae_obj } from "$lib/ae_core/core__idb_dexie";
|
||||
import { db_archives } from "$lib/ae_archives/db_archives";
|
||||
|
||||
import { load_ae_obj_li__archive_content } from "$lib/ae_archives/ae_archives__archive_content";
|
||||
@@ -39,14 +40,37 @@ export async function load_ae_obj_id__archive(
|
||||
params: params,
|
||||
log_lvl: log_lvl
|
||||
})
|
||||
.then(function (archive_obj_get_result) {
|
||||
.then(async function (archive_obj_get_result) {
|
||||
if (archive_obj_get_result) {
|
||||
if (try_cache) {
|
||||
// This is expecting a list
|
||||
db_save_ae_obj_li__archive({
|
||||
obj_type: 'archive',
|
||||
obj_li: [archive_obj_get_result]
|
||||
// Process the results first
|
||||
let processed_obj_li = await process_ae_obj__archive_props({
|
||||
obj_li: [archive_obj_get_result],
|
||||
log_lvl: log_lvl,
|
||||
});
|
||||
if (log_lvl) {
|
||||
console.log('Processed object list:', processed_obj_li);
|
||||
}
|
||||
// Save the updated results list to the database
|
||||
if (log_lvl) {
|
||||
console.log('Saving to DB...');
|
||||
}
|
||||
await db_save_ae_obj_li__ae_obj({
|
||||
db_instance: db_archives,
|
||||
table_name: 'archive',
|
||||
obj_li: processed_obj_li,
|
||||
properties_to_save: properties_to_save,
|
||||
log_lvl: log_lvl,
|
||||
});
|
||||
if (log_lvl) {
|
||||
console.log('DB save completed.');
|
||||
}
|
||||
|
||||
// // This is expecting a list
|
||||
// db_save_ae_obj_li__archive({
|
||||
// obj_type: 'archive',
|
||||
// obj_li: [archive_obj_get_result]
|
||||
// });
|
||||
}
|
||||
return archive_obj_get_result;
|
||||
} else {
|
||||
@@ -180,13 +204,36 @@ export async function load_ae_obj_li__archive(
|
||||
params: params,
|
||||
log_lvl: log_lvl
|
||||
})
|
||||
.then(function (archive_obj_li_get_result) {
|
||||
.then(async function (archive_obj_li_get_result) {
|
||||
if (archive_obj_li_get_result) {
|
||||
if (try_cache) {
|
||||
db_save_ae_obj_li__archive({
|
||||
obj_type: 'archive',
|
||||
obj_li: archive_obj_li_get_result
|
||||
// Process the results first
|
||||
let processed_obj_li = await process_ae_obj__archive_props({
|
||||
obj_li: archive_obj_li_get_result,
|
||||
log_lvl: log_lvl,
|
||||
});
|
||||
if (log_lvl) {
|
||||
console.log('Processed object list:', processed_obj_li);
|
||||
}
|
||||
// Save the updated results list to the database
|
||||
if (log_lvl) {
|
||||
console.log('Saving to DB...');
|
||||
}
|
||||
await db_save_ae_obj_li__ae_obj({
|
||||
db_instance: db_archives,
|
||||
table_name: 'archive',
|
||||
obj_li: processed_obj_li,
|
||||
properties_to_save: properties_to_save,
|
||||
log_lvl: log_lvl,
|
||||
});
|
||||
if (log_lvl) {
|
||||
console.log('DB save completed.');
|
||||
}
|
||||
|
||||
// db_save_ae_obj_li__archive({
|
||||
// obj_type: 'archive',
|
||||
// obj_li: archive_obj_li_get_result
|
||||
// });
|
||||
}
|
||||
return archive_obj_li_get_result;
|
||||
} else {
|
||||
@@ -226,6 +273,10 @@ export async function load_ae_obj_li__archive(
|
||||
if (log_lvl) {
|
||||
console.log(`load_archive_content_obj_li = `, load_archive_content_obj_li);
|
||||
}
|
||||
|
||||
if (load_archive_content_obj_li) {
|
||||
ae_promises.load__event_obj_li[i].archive_content_obj_li = load_archive_content_obj_li;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import type { key_val } from '$lib/ae_stores';
|
||||
import { api } from '$lib/api';
|
||||
|
||||
import { db_save_ae_obj_li__ae_obj } from "$lib/ae_core/core__idb_dexie";
|
||||
import { db_archives } from "$lib/ae_archives/db_archives";
|
||||
|
||||
let ae_promises: key_val = {};
|
||||
@@ -41,12 +42,35 @@ export async function load_ae_obj_id__archive_content(
|
||||
.then(async function (archive_content_obj_get_result) {
|
||||
if (archive_content_obj_get_result) {
|
||||
if (try_cache) {
|
||||
// This is expecting a list
|
||||
await db_save_ae_obj_li__archive_content({
|
||||
obj_type: 'archive_content',
|
||||
obj_li: [archive_content_obj_get_result]
|
||||
|
||||
// Process the results first
|
||||
let processed_obj_li = await process_ae_obj__archive_content_props({
|
||||
obj_li: [archive_content_obj_get_result],
|
||||
log_lvl: log_lvl,
|
||||
});
|
||||
if (log_lvl) {
|
||||
console.log('Processed object list:', processed_obj_li);
|
||||
}
|
||||
// Save the updated results list to the database
|
||||
if (log_lvl) {
|
||||
console.log('Saving to DB...');
|
||||
}
|
||||
await db_save_ae_obj_li__ae_obj({
|
||||
db_instance: db_archives,
|
||||
table_name: 'content',
|
||||
obj_li: processed_obj_li,
|
||||
properties_to_save: properties_to_save,
|
||||
log_lvl: log_lvl,
|
||||
});
|
||||
if (log_lvl) {
|
||||
console.log('DB save completed.');
|
||||
}
|
||||
|
||||
// // This is expecting a list
|
||||
// await db_save_ae_obj_li__archive_content({
|
||||
// obj_type: 'archive_content',
|
||||
// obj_li: [archive_content_obj_get_result]
|
||||
|
||||
// });
|
||||
}
|
||||
return archive_content_obj_get_result;
|
||||
} else {
|
||||
@@ -123,9 +147,32 @@ export async function load_ae_obj_li__archive_content(
|
||||
.then(async function (archive_content_obj_li_get_result) {
|
||||
if (archive_content_obj_li_get_result) {
|
||||
if (try_cache) {
|
||||
await db_save_ae_obj_li__archive_content({
|
||||
obj_type: 'archive_content', obj_li: archive_content_obj_li_get_result
|
||||
// Process the results first
|
||||
let processed_obj_li = await process_ae_obj__archive_content_props({
|
||||
obj_li: archive_content_obj_li_get_result,
|
||||
log_lvl: log_lvl,
|
||||
});
|
||||
if (log_lvl) {
|
||||
console.log('Processed object list:', processed_obj_li);
|
||||
}
|
||||
// Save the updated results list to the database
|
||||
if (log_lvl) {
|
||||
console.log('Saving to DB...');
|
||||
}
|
||||
await db_save_ae_obj_li__ae_obj({
|
||||
db_instance: db_archives,
|
||||
table_name: 'content',
|
||||
obj_li: processed_obj_li,
|
||||
properties_to_save: properties_to_save,
|
||||
log_lvl: log_lvl,
|
||||
});
|
||||
if (log_lvl) {
|
||||
console.log('DB save completed.');
|
||||
}
|
||||
|
||||
// await db_save_ae_obj_li__archive_content({
|
||||
// obj_type: 'archive_content', obj_li: archive_content_obj_li_get_result
|
||||
// });
|
||||
}
|
||||
return archive_content_obj_li_get_result;
|
||||
} else {
|
||||
@@ -530,8 +577,8 @@ export async function process_ae_obj__archive_content_props({
|
||||
updated_on: obj.updated_on,
|
||||
|
||||
// Generated fields for sorting locally only
|
||||
tmp_sort_1: obj.tmp_sort_1,
|
||||
tmp_sort_2: obj.tmp_sort_2,
|
||||
tmp_sort_1: `${obj.original_datetime}_${obj.group}_${obj.priority}_${obj.sort}`,
|
||||
tmp_sort_2: `${obj.group}_${obj.original_datetime}_${obj.priority}_${obj.sort}`,
|
||||
|
||||
// From SQL view
|
||||
archive_code: obj.archive_code,
|
||||
|
||||
@@ -77,6 +77,7 @@ export async function load_ae_obj_id__event(
|
||||
if (log_lvl) {
|
||||
console.log('DB save completed.');
|
||||
}
|
||||
|
||||
// // This is expecting a list
|
||||
// db_save_ae_obj_li__event({
|
||||
// obj_type: 'event',
|
||||
|
||||
@@ -411,12 +411,11 @@ export async function update_ae_obj__journal_entry(
|
||||
try_cache?: boolean,
|
||||
log_lvl?: number;
|
||||
}) {
|
||||
// log_lvl = 1;
|
||||
if (log_lvl) {
|
||||
console.log(`*** update_ae_obj__journal_entry() *** journal_entry_id=${journal_entry_id}`, data_kv);
|
||||
}
|
||||
|
||||
log_lvl = 1;
|
||||
|
||||
// Perform the API update
|
||||
const result = await api.update_ae_obj_id_crud({
|
||||
api_cfg: api_cfg,
|
||||
@@ -481,7 +480,7 @@ export async function db_save_ae_obj_li__journal_entry(
|
||||
log_lvl?: number
|
||||
}
|
||||
) {
|
||||
log_lvl = 1;
|
||||
// log_lvl = 1;
|
||||
if (log_lvl) {
|
||||
console.log(`*** db_save_ae_obj_li__journal_entry() *** obj_type=${obj_type}`, obj_li);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user