@@ -123,8 +123,12 @@ async function renderSidebarHTML() {
123123 }
124124
125125
126+ const currentTime = new Date ( ) . getTime ( ) ;
127+
126128 // 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 ) {
128132
129133 // get repo obj from git
130134 // and save to modified repos
@@ -1506,8 +1510,20 @@ async function renderBranchMenuHTML(renderAll) {
15061510
15071511 let branchResp ;
15081512
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+
15091523 // if repo obj exists
1510- if ( repoObj && repoObj . branches ) {
1524+ if ( repoObj && repoObj . branches &&
1525+ repoObj . branchExpiration !== undefined &&
1526+ repoObj . branchExpiration >= currentTime ) {
15111527
15121528 // get repository branches
15131529 // from repo obj
@@ -1518,34 +1534,46 @@ async function renderBranchMenuHTML(renderAll) {
15181534
15191535 // if branch menu isn't already rendered
15201536 if ( getAttr ( branchMenu , 'tree' ) !== [ user , repoName , contents ] . join ( ) ) {
1521-
1522- setAttr ( branchMenu , 'tree' , [ user , repoName , contents ] . join ( ) ) ;
1523-
1537+
15241538 // show loading message
15251539 branchMenu . innerHTML = '<div class="icon selected"><a>Loading...</a></div>' ;
15261540
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 ;
15471558 }
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+
15491577 }
15501578
15511579
0 commit comments