@@ -1497,22 +1497,13 @@ public List<String> getRepositoryList() {
1497
1497
} else {
1498
1498
// we are caching this list
1499
1499
String msg = "{0} repositories identified in {1} msecs" ;
1500
-
1501
- // optionally (re)calculate repository sizes
1502
1500
if (getBoolean (Keys .web .showRepositorySizes , true )) {
1503
- ByteFormat byteFormat = new ByteFormat ();
1501
+ // optionally (re)calculate repository sizes
1504
1502
msg = "{0} repositories identified with calculated folder sizes in {1} msecs" ;
1505
- for (String repository : repositories ) {
1506
- RepositoryModel model = getRepositoryModel (repository );
1507
- if (!model .skipSizeCalculation ) {
1508
- model .size = byteFormat .format (calculateSize (model ));
1509
- }
1510
- }
1511
- } else {
1512
- // update cache
1513
- for (String repository : repositories ) {
1514
- getRepositoryModel (repository );
1515
- }
1503
+ }
1504
+
1505
+ for (String repository : repositories ) {
1506
+ getRepositoryModel (repository );
1516
1507
}
1517
1508
1518
1509
// rebuild fork networks
@@ -1607,23 +1598,6 @@ public List<RepositoryModel> getRepositoryModels(UserModel user) {
1607
1598
}
1608
1599
}
1609
1600
}
1610
- if (getBoolean (Keys .web .showRepositorySizes , true )) {
1611
- int repoCount = 0 ;
1612
- long startTime = System .currentTimeMillis ();
1613
- ByteFormat byteFormat = new ByteFormat ();
1614
- for (RepositoryModel model : repositories ) {
1615
- if (!model .skipSizeCalculation ) {
1616
- repoCount ++;
1617
- model .size = byteFormat .format (calculateSize (model ));
1618
- }
1619
- }
1620
- long duration = System .currentTimeMillis () - startTime ;
1621
- if (duration > 250 ) {
1622
- // only log calcualtion time if > 250 msecs
1623
- logger .info (MessageFormat .format ("{0} repository sizes calculated in {1} msecs" ,
1624
- repoCount , duration ));
1625
- }
1626
- }
1627
1601
long duration = System .currentTimeMillis () - methodStart ;
1628
1602
logger .info (MessageFormat .format ("{0} repository models loaded for {1} in {2} msecs" ,
1629
1603
repositories .size (), user == null ? "anonymous" : user .username , duration ));
@@ -1706,13 +1680,7 @@ public RepositoryModel getRepositoryModel(String repositoryName) {
1706
1680
model .hasCommits = JGitUtils .hasCommits (r );
1707
1681
}
1708
1682
1709
- LastChange lc = JGitUtils .getLastChange (r );
1710
- model .lastChange = lc .when ;
1711
- model .lastChangeAuthor = lc .who ;
1712
- if (!model .skipSizeCalculation ) {
1713
- ByteFormat byteFormat = new ByteFormat ();
1714
- model .size = byteFormat .format (calculateSize (model ));
1715
- }
1683
+ updateLastChangeFields (r , model );
1716
1684
}
1717
1685
r .close ();
1718
1686
@@ -2011,10 +1979,6 @@ private RepositoryModel loadRepositoryModel(String repositoryName) {
2011
1979
// is symlinked. Use the provided repository name.
2012
1980
model .name = repositoryName ;
2013
1981
}
2014
- model .hasCommits = JGitUtils .hasCommits (r );
2015
- LastChange lc = JGitUtils .getLastChange (r );
2016
- model .lastChange = lc .when ;
2017
- model .lastChangeAuthor = lc .who ;
2018
1982
model .projectPath = StringUtils .getFirstPathElement (repositoryName );
2019
1983
2020
1984
StoredConfig config = r .getConfig ();
@@ -2076,6 +2040,8 @@ private RepositoryModel loadRepositoryModel(String repositoryName) {
2076
2040
model .HEAD = JGitUtils .getHEADRef (r );
2077
2041
model .availableRefs = JGitUtils .getAvailableHeadTargets (r );
2078
2042
model .sparkleshareId = JGitUtils .getSparkleshareId (r );
2043
+ model .hasCommits = JGitUtils .hasCommits (r );
2044
+ updateLastChangeFields (r , model );
2079
2045
r .close ();
2080
2046
2081
2047
if (StringUtils .isEmpty (model .originRepository ) && model .origin != null && model .origin .startsWith ("file://" )) {
@@ -2271,21 +2237,31 @@ private ForkModel getForkModel(String repository) {
2271
2237
}
2272
2238
2273
2239
/**
2274
- * Returns the size in bytes of the repository. Gitblit caches the
2275
- * repository sizes to reduce the performance penalty of recursive
2276
- * calculation. The cache is updated if the repository has been changed
2277
- * since the last calculation.
2240
+ * Updates the last changed fields and optionally calculates the size of the
2241
+ * repository. Gitblit caches the repository sizes to reduce the performance
2242
+ * penalty of recursive calculation. The cache is updated if the repository
2243
+ * has been changed since the last calculation.
2278
2244
*
2279
2245
* @param model
2280
- * @return size in bytes
2246
+ * @return size in bytes of the repository
2281
2247
*/
2282
- public long calculateSize (RepositoryModel model ) {
2283
- if (repositorySizeCache .hasCurrent (model .name , model .lastChange )) {
2284
- return repositorySizeCache .getObject (model .name );
2248
+ public long updateLastChangeFields (Repository r , RepositoryModel model ) {
2249
+ LastChange lc = JGitUtils .getLastChange (r );
2250
+ model .lastChange = lc .when ;
2251
+ model .lastChangeAuthor = lc .who ;
2252
+
2253
+ if (!getBoolean (Keys .web .showRepositorySizes , true ) || model .skipSizeCalculation ) {
2254
+ model .size = null ;
2255
+ return 0L ;
2256
+ }
2257
+ if (!repositorySizeCache .hasCurrent (model .name , model .lastChange )) {
2258
+ File gitDir = r .getDirectory ();
2259
+ long sz = com .gitblit .utils .FileUtils .folderSize (gitDir );
2260
+ repositorySizeCache .updateObject (model .name , model .lastChange , sz );
2285
2261
}
2286
- File gitDir = FileKey . resolve ( new File ( repositoriesFolder , model .name ), FS . DETECTED );
2287
- long size = com . gitblit . utils . FileUtils . folderSize ( gitDir );
2288
- repositorySizeCache . updateObject ( model .name , model . lastChange , size );
2262
+ long size = repositorySizeCache . getObject ( model .name );
2263
+ ByteFormat byteFormat = new ByteFormat ( );
2264
+ model .size = byteFormat . format ( size );
2289
2265
return size ;
2290
2266
}
2291
2267
0 commit comments