Skip to content

Commit 1bc5c5c

Browse files
committed
✨ Improve on the cache handler
1 parent a34a9a8 commit 1bc5c5c

2 files changed

Lines changed: 30 additions & 38 deletions

File tree

main.mjs

Lines changed: 7 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,16 @@ import {
1414
formatMarkdown,
1515
formatDate,
1616
renderIssueDetails,
17-
updateCacheStatus
17+
updateCacheStatus,
18+
handleForceRefresh,
19+
setupLoadButton
1820
} from './shared.mjs';
1921

2022
// Initialize the application
21-
document.addEventListener('DOMContentLoaded', () => {
23+
document.addEventListener('DOMContentLoaded', async () => {
2224
setupCommonUI();
2325
setupAdBanner();
26+
setupLoadButton((repos) => loadAllRepositories(repos, true));
2427

2528
const initialRepos = getInitialRepos();
2629

@@ -31,37 +34,11 @@ document.addEventListener('DOMContentLoaded', () => {
3134
url.searchParams.set('repos', initialRepos.join(','));
3235
window.history.replaceState({}, '', url);
3336

34-
loadAllRepositories(initialRepos, true);
35-
}
36-
37-
// Setup load button handler
38-
const loadBtn = document.getElementById('loadBtn');
39-
loadBtn.addEventListener('click', async () => {
40-
setGitHubToken(document.getElementById('token').value.trim());
41-
const reposText = document.getElementById('repos').value.trim();
42-
43-
// Save to localStorage
44-
localStorage.setItem('githubRepos', reposText);
45-
46-
if (!reposText) {
47-
showError('Please enter at least one repository');
48-
return;
49-
}
50-
51-
const repos = reposText.split('\n')
52-
.map(line => line.trim())
53-
.filter(line => line && line.includes('/'));
54-
55-
if (repos.length === 0) {
56-
showError('Please enter valid repositories in format: owner/repo');
57-
return;
58-
}
59-
60-
await loadAllRepositories(repos, true);
37+
await loadAllRepositories(initialRepos, true);
6138

6239
// Update cache status after loading
6340
updateCacheStatus();
64-
});
41+
}
6542

6643
// Setup issue detail panel handlers
6744
const iframePanel = document.getElementById('iframePanel');

shared.mjs

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// GitHub API configuration
22
const GITHUB_API_BASE = 'https://api.github.com';
33

4-
// Cache configuration (15 minutes default)
5-
const CACHE_DURATION_MS = 15 * 60 * 1000;
4+
// Cache configuration (1 hour default)
5+
const CACHE_DURATION_MS = 60 * 60 * 1000;
66
const CACHE_KEY_PREFIX = 'github_cache_';
77

88
// State
@@ -219,9 +219,11 @@ export async function fetchRepositoryData(repo, openOnly = false) {
219219
// Check cache first
220220
const cached = getCachedData(repo, openOnly);
221221
if (cached) {
222+
console.log(`Using cache for ${repo}`);
222223
return cached;
223224
}
224225

226+
console.log(`Fetching fresh data for ${repo}`);
225227
try {
226228
const state = openOnly ? 'open' : 'all';
227229
const issuesAndPRsUrl = `${GITHUB_API_BASE}/repos/${owner}/${repoName}/issues?state=${state}&per_page=100`;
@@ -461,6 +463,21 @@ export function getCacheAgeText(repoData) {
461463
return `📦 Cached ${timeAgo} (expires in ${remainingMinutes}m)`;
462464
}
463465

466+
/**
467+
* Handle force refresh - clears cache if checkbox is checked
468+
*/
469+
export function handleForceRefresh(repos) {
470+
const forceRefresh = document.getElementById('forceRefresh');
471+
if (forceRefresh && forceRefresh.checked) {
472+
const clearedCount = clearCache(repos);
473+
console.log(`Force refresh: cleared ${clearedCount} cache entries for`, repos);
474+
// Uncheck the box after clearing
475+
forceRefresh.checked = false;
476+
return true;
477+
}
478+
return false;
479+
}
480+
464481
/**
465482
* Get initial repositories (from query string or textarea)
466483
*/
@@ -522,15 +539,13 @@ export function setupLoadButton(onLoad) {
522539
url.searchParams.set('repos', repos.join(','));
523540
window.history.pushState({}, '', url);
524541

525-
// Clear cache for selected repos if force refresh is checked
526-
if (forceRefresh && forceRefresh.checked) {
527-
clearCache(repos);
528-
}
542+
// Handle force refresh
543+
handleForceRefresh(repos);
529544

530545
await onLoad(repos);
531546

532-
// Update cache status after loading
533-
updateCacheStatus();
547+
// Update cache status after loading (with small delay to ensure cache writes complete)
548+
setTimeout(() => updateCacheStatus(), 100);
534549
});
535550

536551
// Setup share button

0 commit comments

Comments
 (0)