Skip to content

Commit

Permalink
load data faster
Browse files Browse the repository at this point in the history
  • Loading branch information
strukturart committed Mar 12, 2024
1 parent 0d55a56 commit fa0dfac
Show file tree
Hide file tree
Showing 7 changed files with 3,870 additions and 683 deletions.
74 changes: 39 additions & 35 deletions application/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,6 @@ async function getClientInstance(item) {
});
}
if (item.type === 'basic') {
console.log(item.type, item.user, item.password);
clientInstances[item.id] = new DAVClient({
serverUrl: item.server_url,
credentials: {
Expand All @@ -427,7 +426,6 @@ async function getClientInstance(item) {
});
}
}
console.log(clientInstances[item.id]);
return clientInstances[item.id];
} catch (e) {
console.error('Error occurred while creating DAVClient instance:', e);
Expand All @@ -440,31 +438,39 @@ async function getClientInstance(item) {
async function load_caldav(callback = false, account_to_update = false) {
if (!navigator.onLine) return false;
closing_prohibited = true;
//remove events with local events
try {
parsed_events = parsed_events.filter((e) => !e.isCaldav);
} catch (e) {}

//remove events
if (!account_to_update) {
try {
parsed_events = parsed_events.filter((e) => !e.isCaldav);
} catch (e) {
console.log(e);
}
} else {
try {
parsed_events = parsed_events.filter((e) => e.id == e.account_to_update);
} catch (e) {
console.log(e);
}
}

// Load data from every account or singel account
for (const item of accounts) {
if (account_to_update != false && account_to_update !== item) continue;
console.log(isLoggedInMap);
const client = await getClientInstance(item);
console.log('client' + JSON.stringify(client));
let calendars;
try {
calendars = await client.fetchCalendars();
} catch (fetchCalendarsError) {
console.log(fetchCalendarsError);
if (account_to_update != false && account_to_update !== item) {
continue;
}

const client = await getClientInstance(item);

try {
if (!isLoggedInMap[item.id]) {
try {
await client.login();

isLoggedInMap[item.id] = true;
console.log('login successfull');
} catch (loginError) {
console.log(loginError);
console.log('cant login' + loginError);
isLoggedInMap[item.id] = false; // Set flag to indicate login failure
continue; // Skip to the next account in case of login failure
}
Expand All @@ -475,10 +481,10 @@ async function load_caldav(callback = false, account_to_update = false) {
let calendars;
try {
calendars = await client.fetchCalendars();
console.log(calendars);
} catch (fetchCalendarsError) {
console.log(fetchCalendarsError);

// Handle the error (e.g., show a user-friendly message)
continue; // Skip to the next account in case of fetch failure
}

Expand Down Expand Up @@ -508,7 +514,6 @@ async function load_caldav(callback = false, account_to_update = false) {
}

// Parse data

for (const obj of objects) {
if (
'serviceWorker' in navigator &&
Expand Down Expand Up @@ -594,7 +599,7 @@ let cache_caldav = async function () {
}
}
//cache parsed events
cache_caldav_events();
// cache_caldav_events();
};

//default calendar
Expand Down Expand Up @@ -671,7 +676,7 @@ export let sync_caldav = async function (callback) {
callback(item);
break;
} else {
if (!status.visible) cache_caldav_events(true);
// if (!status.visible) cache_caldav_events(true);
}
} catch (e) {
if (!navigator.onLine)
Expand Down Expand Up @@ -714,21 +719,21 @@ export let sync_caldav = async function (callback) {
//load cached

const load_cached_caldav = async () => {
let should_be_loaded = false;

if (!accounts) {
return false;
}

for (const item of accounts) {
try {
const w = await localforage.getItem(item.id);

// Load content if never cached
if (w === null) {
should_be_loaded = true;
try {
load_caldav(false, item.id);
} catch (e) {
console.log(e);
}
}

for (const b of w) {
for (const m of b.objects) {
if (
Expand All @@ -755,11 +760,6 @@ const load_cached_caldav = async () => {
console.log(e);
}
}

if (should_be_loaded) {
console.log('try to load');
load_caldav(false, false);
}
};

//create event
Expand Down Expand Up @@ -838,11 +838,14 @@ export let create_caldav = async function (

//delete event
export let delete_caldav = async function (etag, url, account_id, uid) {
console.log(parsed_events);
if (!navigator.onLine) return false;

document.querySelector('.loading-spinner').style.display = 'block';
const matchingAccount = accounts.find((p) => p.id === account_id);

console.log('hey' + matchingAccount);

if (matchingAccount == undefined) {
document.querySelector('.loading-spinner').style.display = 'none';
side_toaster('There was a problem deleting, please try again later.', 5000);
Expand Down Expand Up @@ -1028,7 +1031,7 @@ const load_subscriptions = async () => {
export let sync_caldav_callback = function (account_to_update) {
load_caldav(false, account_to_update).then(() => {
if (!status.visible) {
cache_caldav_events(true);
//cache_caldav_events(true);
}
});
};
Expand Down Expand Up @@ -4882,7 +4885,7 @@ let delete_event = function (etag, url, account_id, uid) {
if (etag) {
delete_caldav(etag, url, account_id, uid).then((e) => {
if (status.shortCut) show_success_animation();
cache_caldav_events();
// cache_caldav_events();
});
} else {
// Find the index of the object with the matching UID
Expand All @@ -4900,7 +4903,7 @@ let delete_event = function (etag, url, account_id, uid) {
get_last_view();
}
show_success_animation();
cache_caldav_events();
// cache_caldav_events();
})
.catch(function (err) {});
}
Expand Down Expand Up @@ -5063,7 +5066,8 @@ function shortpress_action(param) {
//parsed_events = [];
//load_cached_caldav();
//load_or_create_local_account();
load_subscriptions();
// load_subscriptions();
load_caldav();

break;
case '5':
Expand Down Expand Up @@ -5541,7 +5545,7 @@ let interval = () => {
sort_array(parsed_events, 'dateStartUnix', 'number');
clearInterval(waitForNoMessages);
//cache parsed data
cache_caldav_events();
// cache_caldav_events();
}
}, checkMessagesInterval);
};
Expand Down
2 changes: 1 addition & 1 deletion application/manifest.webapp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "2.2.6311",
"version": "2.2.6314",
"name": "greg",
"id": "greg",
"categories": ["utilities"],
Expand Down
15 changes: 11 additions & 4 deletions application/sw.js
Original file line number Diff line number Diff line change
Expand Up @@ -332,21 +332,28 @@ self.addEventListener('message', async (event) => {
if (event.data.type == 'parse') {
try {
let is_caldav = () => {
if (event.data.e == 'subscription' || event.data.e == 'local-id')
if (event.data.e == 'subscription' || event.data.e == 'local-id') {
return false;
} else {
return true;
}
};

let is_subscription = () => {
if (event.data.e == 'subscription') return true;
if (event.data.e == 'subscription') {
return true;
} else {
return false;
}
};

let ff = parse_ics(
event.data.t.data,
event.data.e == is_subscription(),
is_subscription(),
event.data.t.etag,
event.data.t.url,
event.data.e,
event.data.e == is_caldav(),
is_caldav(),
false,
event.data.callback || false,
event.data.store || false
Expand Down
Binary file modified images/kaios-marketing-banner.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit fa0dfac

Please sign in to comment.