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

Fixing broken cache in text filter #72

Closed
Closed
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
35 changes: 19 additions & 16 deletions src/home/fetch-github/fetch-and-display-previews.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,27 @@ export async function fetchAndDisplayPreviewsFromCache(sorting?: Sorting, option
return fetchAndDisplayPreviewsFromNetwork(sorting, options);
}

// makes sure tasks have a timestamp to know how old the cache is, or refresh if older than 15 minutes
if (!_cachedTasks || !_cachedTasks.timestamp || _cachedTasks.timestamp + 60 * 1000 * 15 <= Date.now()) {
_cachedTasks = {
timestamp: Date.now(),
tasks: [],
loggedIn: _accessToken !== null,
};
}

const cachedTasks = _cachedTasks.tasks as TaskMaybeFull[];
taskManager.syncTasks(cachedTasks);
try {
// makes sure tasks have a timestamp to know how old the cache is, or refresh if older than 15 minutes
if (!_cachedTasks || !_cachedTasks.timestamp || _cachedTasks.timestamp + 60 * 1000 * 15 <= Date.now()) {
_cachedTasks = {
timestamp: Date.now(),
tasks: [],
loggedIn: _accessToken !== null,
};
}
const cachedTasks = _cachedTasks.tasks as TaskMaybeFull[];
taskManager.syncTasks(cachedTasks);

if (!cachedTasks.length) {
// load from network if there are no cached issues
if (!cachedTasks.length) {
// load from network if there are no cached issues
return fetchAndDisplayPreviewsFromNetwork(sorting, options);
} else {
displayGitHubIssues(sorting, options);
return fetchAvatars();
}
} catch (cacheError) {
return fetchAndDisplayPreviewsFromNetwork(sorting, options);
} else {
displayGitHubIssues(sorting, options);
return fetchAvatars();
}
}

Expand Down