@@ -1497,22 +1497,13 @@ public List<String> getRepositoryList() {
14971497 } else {
14981498 // we are caching this list
14991499 String msg = "{0} repositories identified in {1} msecs" ;
1500-
1501- // optionally (re)calculate repository sizes
15021500 if (getBoolean (Keys .web .showRepositorySizes , true )) {
1503- ByteFormat byteFormat = new ByteFormat ();
1501+ // optionally (re)calculate repository sizes
15041502 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 );
15161507 }
15171508
15181509 // rebuild fork networks
@@ -1607,23 +1598,6 @@ public List<RepositoryModel> getRepositoryModels(UserModel user) {
16071598 }
16081599 }
16091600 }
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- }
16271601 long duration = System .currentTimeMillis () - methodStart ;
16281602 logger .info (MessageFormat .format ("{0} repository models loaded for {1} in {2} msecs" ,
16291603 repositories .size (), user == null ? "anonymous" : user .username , duration ));
@@ -1706,13 +1680,7 @@ public RepositoryModel getRepositoryModel(String repositoryName) {
17061680 model .hasCommits = JGitUtils .hasCommits (r );
17071681 }
17081682
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 );
17161684 }
17171685 r .close ();
17181686
@@ -2011,10 +1979,6 @@ private RepositoryModel loadRepositoryModel(String repositoryName) {
20111979 // is symlinked. Use the provided repository name.
20121980 model .name = repositoryName ;
20131981 }
2014- model .hasCommits = JGitUtils .hasCommits (r );
2015- LastChange lc = JGitUtils .getLastChange (r );
2016- model .lastChange = lc .when ;
2017- model .lastChangeAuthor = lc .who ;
20181982 model .projectPath = StringUtils .getFirstPathElement (repositoryName );
20191983
20201984 StoredConfig config = r .getConfig ();
@@ -2076,6 +2040,8 @@ private RepositoryModel loadRepositoryModel(String repositoryName) {
20762040 model .HEAD = JGitUtils .getHEADRef (r );
20772041 model .availableRefs = JGitUtils .getAvailableHeadTargets (r );
20782042 model .sparkleshareId = JGitUtils .getSparkleshareId (r );
2043+ model .hasCommits = JGitUtils .hasCommits (r );
2044+ updateLastChangeFields (r , model );
20792045 r .close ();
20802046
20812047 if (StringUtils .isEmpty (model .originRepository ) && model .origin != null && model .origin .startsWith ("file://" )) {
@@ -2271,21 +2237,31 @@ private ForkModel getForkModel(String repository) {
22712237 }
22722238
22732239 /**
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.
22782244 *
22792245 * @param model
2280- * @return size in bytes
2246+ * @return size in bytes of the repository
22812247 */
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 );
22852261 }
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 );
22892265 return size ;
22902266 }
22912267
0 commit comments