Skip to content

Commit e382496

Browse files
authored
Fix #204
Update filebrowser.js
2 parents e074124 + 1cb4ec4 commit e382496

File tree

4 files changed

+92
-32
lines changed

4 files changed

+92
-32
lines changed

filebrowser.js

+54-26
Original file line numberDiff line numberDiff line change
@@ -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

full.css

-1
Original file line numberDiff line numberDiff line change
@@ -778,7 +778,6 @@ body.notransition .sidebar {
778778
height: 2px;
779779
width: var(--sidebar-width);
780780
margin-bottom: -2px;
781-
border-radius: 6px;
782781
pointer-events: none;
783782
background: #568af2;
784783
background: var(--rosemary-lighter);

repos.js

+37-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
// create a repository object
33
function createRepoObj(fullName, selBranch, defaultBranch,
44
pushAccess, branches, private,
5-
isFork, empty) {
5+
isFork, empty,
6+
repoDataExpiration, branchExpiration) {
67

78
return {
89
fullName,
@@ -12,7 +13,9 @@ function createRepoObj(fullName, selBranch, defaultBranch,
1213
branches,
1314
private,
1415
isFork,
15-
empty
16+
empty,
17+
repoDataExpiration,
18+
branchExpiration,
1619
}
1720

1821
}
@@ -86,6 +89,22 @@ function updateModRepoEmptyStatus(fullName, empty) {
8689

8790
}
8891

92+
function updateModRepoDataExpiration(fullName, time) {
93+
94+
modifiedRepos[fullName].repoDataExpiration = time;
95+
96+
updateModReposLS();
97+
98+
}
99+
100+
function updateModRepoBranchExpiration(fullName, time) {
101+
102+
modifiedRepos[fullName].branchExpiration = time;
103+
104+
updateModReposLS();
105+
106+
}
107+
89108

90109

91110
// get repo obj from git
@@ -102,7 +121,7 @@ async function fetchRepoAndSaveToModRepos(treeLoc) {
102121

103122
// create temporary repo object
104123
const tempRepoObj = createRepoObj(fullName, selBranch, null,
105-
null, null, null, null, null);
124+
null, null, null, null, null, 0, 0);
106125

107126
// add temp repo object
108127
// to modified repos
@@ -127,6 +146,16 @@ async function fetchRepoAndSaveToModRepos(treeLoc) {
127146
// check temp repo changed
128147
const tempRepo = modifiedRepos[fullName];
129148

149+
150+
// get repo data expiration time
151+
// (two months from now)
152+
153+
let expirationDate = new Date();
154+
expirationDate.setDate(expirationDate.getDate() + (2 * 4 * 7));
155+
156+
const twoMonthsTime = expirationDate.getTime();
157+
158+
130159
// create repo obj
131160
const repoObj = createRepoObj(fullName,
132161

@@ -140,7 +169,11 @@ async function fetchRepoAndSaveToModRepos(treeLoc) {
140169

141170
repo.private, repo.fork,
142171

143-
(tempRepo.empty ?? false));
172+
(tempRepo.empty ?? false),
173+
174+
twoMonthsTime,
175+
176+
tempRepo.branchExpiration);
144177

145178
// add repo object
146179
// to modified repos

worker/client-channel.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55

66
// update worker name when updating worker
7-
const WORKER_NAME = 'codeit-worker-v556';
7+
const WORKER_NAME = 'codeit-worker-v558';
88

99

1010
// internal paths

0 commit comments

Comments
 (0)