Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fermata fixes apr17 #1146

Merged
merged 3 commits into from
Apr 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions www/js/config/dynamicConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,11 @@ function cacheResourcesFromConfig(config: AppConfig) {
if (config.survey_info?.surveys) {
Object.values(config.survey_info.surveys).forEach((survey) => {
if (!survey?.['formPath']) throw new Error(i18next.t('config.survey-missing-formpath'));
fetchUrlCached(survey['formPath']);
fetchUrlCached(survey['formPath'], { cache: 'reload' });
});
}
if (config.label_options) {
fetchUrlCached(config.label_options);
fetchUrlCached(config.label_options, { cache: 'reload' });
}
}

Expand Down
2 changes: 1 addition & 1 deletion www/js/diary/timelineHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ export async function updateUnprocessedBleScans(queryRange: TimestampRange) {
endTs: queryRange.end_ts,
};
const getMethod = window['cordova'].plugins.BEMUserCache.getSensorDataForInterval;
getUnifiedDataForInterval('background/bluetooth_ble', tq, getMethod).then(
await getUnifiedDataForInterval('background/bluetooth_ble', tq, getMethod).then(
(bleScans: BEMData<BluetoothBleData>[]) => {
logDebug(`Read ${bleScans.length} BLE scans`);
unprocessedBleScans = bleScans;
Expand Down
9 changes: 5 additions & 4 deletions www/js/services/commHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,18 @@ import { TimestampRange } from '../types/diaryTypes';

/**
* @param url URL endpoint for the request
* @param fetchOpts (optional) options for the fetch request. If 'cache' is set to 'reload', the cache will be ignored
* @returns Promise of the fetched response (as text) or cached text from local storage
*/
export async function fetchUrlCached(url) {
export async function fetchUrlCached(url: string, fetchOpts?: RequestInit) {
const stored = localStorage.getItem(url);
if (stored) {
if (stored && fetchOpts?.cache != 'reload') {
logDebug(`fetchUrlCached: found cached data for url ${url}, returning`);
return Promise.resolve(stored);
}
try {
logDebug(`fetchUrlCached: found no cached data for url ${url}, fetching`);
const response = await fetch(url);
logDebug(`fetchUrlCached: cache had ${stored} for url ${url}, not using; fetching`);
const response = await fetch(url, fetchOpts);
Comment on lines +18 to +19
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just for my own understanding, we also cache separately in the localStorage. This is just to ensure that the HTTP cache (if any) also does not return obsolete values. The log statement prints the value from the localStorage cache.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct

const text = await response.text();
localStorage.setItem(url, text);
logDebug(`fetchUrlCached: fetched data for url ${url}, returning`);
Expand Down
1 change: 1 addition & 0 deletions www/js/survey/enketo/UserInputButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const UserInputButton = ({ timelineEntry }: Props) => {

// which survey will this button launch?
const [surveyName, notFilledInLabel] = useMemo(() => {
if (!appConfig) return []; // no config loaded yet; show blank for now
const tripLabelConfig = appConfig?.survey_info?.buttons?.['trip-label'];
if (!tripLabelConfig) {
// config doesn't specify; use default
Expand Down
Loading