@@ -142,7 +142,7 @@ function allIncluded() {
142
142
return WeekDisplayPadded ;
143
143
}
144
144
145
- const DEBUG = true ;
145
+ const DEBUG = false ;
146
146
function log ( ...args ) {
147
147
if ( DEBUG ) {
148
148
console . log ( `[SCRUM-HELPER]:` , ...args ) ;
@@ -165,13 +165,8 @@ function allIncluded() {
165
165
errorTTL : 60 * 1000 , // 1 min error cache
166
166
subject : null ,
167
167
} ;
168
- const MAX_CACHE_SIZE = 50 * 1024 * 1024 ; //50mb max cache
169
-
168
+
170
169
function saveToStorage ( data , subject = null ) {
171
- if ( data === githubCache . data && subject === githubCache . subject ) {
172
- log ( 'Skipping cache save - no changes' ) ;
173
- return Promise . resolve ( true ) ;
174
- }
175
170
const cacheData = {
176
171
data : data ,
177
172
cacheKey : githubCache . cacheKey ,
@@ -191,6 +186,8 @@ function allIncluded() {
191
186
resolve ( false ) ;
192
187
} else {
193
188
log ( 'Cache saved successfuly' ) ;
189
+ githubCache . data = data ;
190
+ githubCache . subject = subject ;
194
191
resolve ( true ) ;
195
192
}
196
193
} ) ;
@@ -201,19 +198,19 @@ function allIncluded() {
201
198
log ( 'Loading cache from storage' ) ;
202
199
return new Promise ( ( resolve ) => {
203
200
chrome . storage . local . get ( 'githubCache' , ( result ) => {
204
- if ( chrome . runtime . lastError ) {
205
- logError ( 'Storage load failed:' , chrome . runtime . lastError ) ;
206
- resolve ( false ) ;
207
- return ;
208
- }
209
-
210
201
const cache = result . githubCache ;
211
202
if ( ! cache ) {
212
203
log ( 'No cache found in storage' ) ;
213
204
resolve ( false ) ;
214
205
return ;
215
206
}
216
- log ( 'Found cache:' , {
207
+ const isCacheExpired = ( Date . now ( ) - cache . timestamp ) > githubCache . ttl ;
208
+ if ( isCacheExpired ) {
209
+ log ( 'Cached data is expired' ) ;
210
+ resolve ( false ) ;
211
+ return ;
212
+ }
213
+ log ( 'Found valid cache:' , {
217
214
cacheKey : cache . cacheKey ,
218
215
age : `${ ( ( Date . now ( ) - cache . timestamp ) / 1000 / 60 ) . toFixed ( 1 ) } minutes` ,
219
216
} ) ;
@@ -223,28 +220,15 @@ function allIncluded() {
223
220
githubCache . timestamp = cache . timestamp ;
224
221
githubCache . subject = cache . subject ;
225
222
226
- // use cached subject element
227
223
if ( cache . subject && scrumSubject ) {
228
224
scrumSubject . value = cache . subject ;
229
225
scrumSubject . dispatchEvent ( new Event ( 'input' , { bubbles : true } ) ) ;
230
226
}
231
-
232
227
resolve ( true ) ;
233
228
} )
234
229
} )
235
230
}
236
-
237
- function updateCache ( data ) {
238
- const cacheSize = new Blob ( [ JSON . stringify ( data ) ] ) . size ;
239
- if ( cacheSize > MAX_CACHE_SIZE ) {
240
- console . wanr ( `Cache data too large, not caching` ) ;
241
- return ;
242
- }
243
- githubCache . data = data ;
244
- githubCache . timestamp = Date . now ( ) ;
245
- }
246
-
247
- // fetch github data
231
+
248
232
async function fetchGithubData ( ) {
249
233
const cacheKey = `${ githubUsername } -${ startingDate } -${ endingDate } ` ;
250
234
@@ -322,8 +306,7 @@ function allIncluded() {
322
306
githubCache . data = { githubIssuesData, githubPrsReviewData, githubUserData } ;
323
307
githubCache . timestamp = Date . now ( ) ;
324
308
325
- // updateCache({ githubIssuesData, githubPrsReviewData, githubUserData });
326
- await saveToStorage ( githubCache . data ) ; // Save to storage
309
+ await saveToStorage ( githubCache . data ) ;
327
310
processGithubData ( githubCache . data ) ;
328
311
329
312
// Resolve queued calls
@@ -362,6 +345,38 @@ function allIncluded() {
362
345
}
363
346
verifyCacheStatus ( ) ;
364
347
348
+ async function forceGithubDataRefresh ( ) {
349
+ log ( 'Force refreshing GitHub data' ) ;
350
+ // clear cache
351
+ githubCache = {
352
+ data : null ,
353
+ cacheKey : null ,
354
+ timestamp : 0 ,
355
+ ttl : 10 * 60 * 1000 ,
356
+ fetching : false ,
357
+ queue : [ ] ,
358
+ errors : { } ,
359
+ errorTTL : 60 * 1000 ,
360
+ subject : null
361
+ } ;
362
+ await new Promise ( resolve => {
363
+ chrome . storage . local . remove ( 'githubCache' , resolve ) ;
364
+ } ) ;
365
+
366
+ log ( 'Cache cleared, fetching fresh data' ) ;
367
+ try {
368
+ await fetchGithubData ( ) ;
369
+ await saveToStorage ( ) ;
370
+ return { success : true , timestamp : Date . now ( ) } ;
371
+ } catch ( err ) {
372
+ logError ( 'Force refresh failed:' , err ) ;
373
+ throw err ;
374
+ }
375
+ }
376
+ if ( typeof window !== 'undefined' ) {
377
+ window . forceGithubDataRefresh = forceGithubDataRefresh ;
378
+ }
379
+
365
380
function processGithubData ( data ) {
366
381
log ( 'Processing Github data' ) ;
367
382
githubIssuesData = data . githubIssuesData ;
@@ -433,24 +448,11 @@ function allIncluded() {
433
448
} ) ;
434
449
}
435
450
436
- // depriciate this
437
- // function getProject() {
438
- // if (projectName != '') return projectName;
439
-
440
- // let project = '<project name>';
441
- // let url = window.location.href;
442
- // let projectUrl = url.substr(url.lastIndexOf('/') + 1);
443
- // if (projectUrl === 'susiai') project = 'SUSI.AI';
444
- // else if (projectUrl === 'open-event') project = 'Open Event';
445
- // return project;
446
- // }
447
-
448
451
//load initial scrum subject
449
452
function scrumSubjectLoaded ( ) {
450
453
if ( ! enableToggle ) return ;
451
454
setTimeout ( ( ) => {
452
455
let name = githubUserData . name || githubUsername ;
453
- // let project = getProject();
454
456
let project = projectName || '<project name>' ;
455
457
let curDate = new Date ( ) ;
456
458
let year = curDate . getFullYear ( ) . toString ( ) ;
@@ -463,7 +465,6 @@ function allIncluded() {
463
465
464
466
const subject = `[Scrum] ${ name } - ${ project } - ${ dateCode } - False` ;
465
467
log ( 'Generated subject:' , subject ) ;
466
- // Save subject to cache
467
468
githubCache . subject = subject ;
468
469
saveToStorage ( githubCache . data , subject ) ;
469
470
@@ -738,3 +739,12 @@ $('button>span:contains(New conversation)')
738
739
allIncluded ( ) ;
739
740
} ) ;
740
741
742
+ chrome . runtime . onMessage . addListener ( ( request , sender , sendResponse ) => {
743
+ if ( request . action === 'forceRefresh' ) {
744
+ forceGithubDataRefresh ( ) . then ( result => sendResponse ( result ) ) . catch ( err => {
745
+ console . error ( 'Force refresh failed:' , err ) ;
746
+ sendResponse ( { success : false , error : err . message } ) ;
747
+ } ) ;
748
+ return true ;
749
+ }
750
+ } )
0 commit comments