@@ -123,8 +123,12 @@ async function renderSidebarHTML() {
123
123
}
124
124
125
125
126
+ const currentTime = new Date ( ) . getTime ( ) ;
127
+
126
128
// if repo obj dosen't exist
127
- if ( ! repoObj || ! repoObj . defaultBranch ) {
129
+ if ( ! repoObj || ! repoObj . defaultBranch
130
+ || repoObj . repoDataExpiration === undefined || repoObj . branchExpiration === undefined
131
+ || repoObj . repoDataExpiration < currentTime ) {
128
132
129
133
// get repo obj from git
130
134
// and save to modified repos
@@ -1506,8 +1510,20 @@ async function renderBranchMenuHTML(renderAll) {
1506
1510
1507
1511
let branchResp ;
1508
1512
1513
+
1514
+ // get current time
1515
+
1516
+ let currentDate = new Date ( ) ;
1517
+ const currentTime = currentDate . getTime ( ) ;
1518
+
1519
+ currentDate . setDate ( currentDate . getDate ( ) + 1 ) ;
1520
+ const dayFromNow = currentDate . getTime ( ) ;
1521
+
1522
+
1509
1523
// if repo obj exists
1510
- if ( repoObj && repoObj . branches ) {
1524
+ if ( repoObj && repoObj . branches &&
1525
+ repoObj . branchExpiration !== undefined &&
1526
+ repoObj . branchExpiration >= currentTime ) {
1511
1527
1512
1528
// get repository branches
1513
1529
// from repo obj
@@ -1518,34 +1534,46 @@ async function renderBranchMenuHTML(renderAll) {
1518
1534
1519
1535
// if branch menu isn't already rendered
1520
1536
if ( getAttr ( branchMenu , 'tree' ) !== [ user , repoName , contents ] . join ( ) ) {
1521
-
1522
- setAttr ( branchMenu , 'tree' , [ user , repoName , contents ] . join ( ) ) ;
1523
-
1537
+
1524
1538
// show loading message
1525
1539
branchMenu . innerHTML = '<div class="icon selected"><a>Loading...</a></div>' ;
1526
1540
1527
- // if branch resp isn't already stored
1528
- // in local storage
1529
- if ( ! repoObj || ! repoObj . branches ) {
1530
-
1531
- // get branches for repository
1532
- branchResp = await git . getBranches ( treeLoc ) ;
1533
-
1534
- // if repo dosen't exist, return
1535
- if ( branchResp . message ) {
1536
- return ;
1537
- }
1538
-
1539
- // clean resp and save only relevant fields
1540
- const cleanedResp = branchResp . map ( branch => {
1541
- return { name : branch . name , commit : { sha : branch . commit . sha } } ;
1542
- } ) ;
1543
-
1544
- // save branch resp in local storage
1545
- updateModRepoBranches ( fullName , cleanedResp ) ;
1546
-
1541
+ setAttr ( branchMenu , 'tree' , [ user , repoName , contents ] . join ( ) ) ;
1542
+
1543
+ }
1544
+
1545
+
1546
+ // if branch resp isn't already stored
1547
+ // in local storage
1548
+ if ( ! repoObj || ! repoObj . branches ||
1549
+ repoObj . branchExpiration === undefined ||
1550
+ repoObj . branchExpiration < currentTime ) {
1551
+
1552
+ // get branches for repository
1553
+ branchResp = await git . getBranches ( treeLoc ) ;
1554
+
1555
+ // if repo dosen't exist, return
1556
+ if ( branchResp . message ) {
1557
+ return ;
1547
1558
}
1548
-
1559
+
1560
+ // clean resp and save only relevant fields
1561
+ const cleanedResp = branchResp . map ( branch => {
1562
+ return {
1563
+ name : branch . name ,
1564
+ commit : {
1565
+ sha : branch . commit . sha
1566
+ }
1567
+ } ;
1568
+ } ) ;
1569
+
1570
+ // save branch resp in local storage
1571
+ updateModRepoBranches ( fullName , cleanedResp ) ;
1572
+
1573
+ // save branch expiration date
1574
+ // in local storage
1575
+ updateModRepoBranchExpiration ( fullName , dayFromNow ) ;
1576
+
1549
1577
}
1550
1578
1551
1579
0 commit comments