mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-07-12 04:02:39 +02:00
improve cache for repository commands
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
/**
|
||||
* Copyright (c) 2010, Sebastian Sdorra All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer. 2. Redistributions in
|
||||
* binary form must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution. 3. Neither the name of SCM-Manager;
|
||||
* nor the names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* http://bitbucket.org/sdorra/scm-manager
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package sonia.scm.repository;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import sonia.scm.Filter;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
* @since 1.17
|
||||
*
|
||||
* @param <T>
|
||||
*/
|
||||
public class RepositoryCacheKeyFilter<T extends RepositoryCacheKey>
|
||||
implements Filter<T>
|
||||
{
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
*
|
||||
* @param repositoryId
|
||||
*/
|
||||
public RepositoryCacheKeyFilter(String repositoryId)
|
||||
{
|
||||
this.repositoryId = repositoryId;
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param item
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean accept(T item)
|
||||
{
|
||||
return repositoryId.equals(item.getRepositoryId());
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
private String repositoryId;
|
||||
}
|
||||
@@ -46,6 +46,7 @@ import sonia.scm.cache.Cache;
|
||||
import sonia.scm.cache.CacheManager;
|
||||
import sonia.scm.repository.BlameResult;
|
||||
import sonia.scm.repository.Repository;
|
||||
import sonia.scm.repository.RepositoryCacheKey;
|
||||
import sonia.scm.repository.RepositoryException;
|
||||
import sonia.scm.repository.spi.BlameCommand;
|
||||
import sonia.scm.repository.spi.BlameCommandRequest;
|
||||
@@ -62,13 +63,13 @@ import java.io.Serializable;
|
||||
* <b>Sample:</b>
|
||||
* <br />
|
||||
* <br />
|
||||
* Print each line number and code of the file scm-core/pom.xml at
|
||||
* Print each line number and code of the file scm-core/pom.xml at
|
||||
* revision 60c2f2783368:<br />
|
||||
* <pre><code>
|
||||
* BlameCommandBuilder blame = repositoryService.getBlameCommand();
|
||||
* BlameResult result = blame.setRevision("60c2f2783368")
|
||||
* .getBlameResult("scm-core/pom.xml");
|
||||
*
|
||||
*
|
||||
* for ( BlameLine line : result ){
|
||||
* System.out.println(line.getLineNumber() + ": " + line.getCode());
|
||||
* }
|
||||
@@ -228,7 +229,7 @@ public final class BlameCommandBuilder
|
||||
* @version Enter version here..., 12/06/05
|
||||
* @author Enter your name here...
|
||||
*/
|
||||
static class CacheKey implements Serializable
|
||||
static class CacheKey implements RepositoryCacheKey, Serializable
|
||||
{
|
||||
|
||||
/**
|
||||
@@ -293,7 +294,8 @@ public final class BlameCommandBuilder
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
String getRepositoryId()
|
||||
@Override
|
||||
public String getRepositoryId()
|
||||
{
|
||||
return repositoryId;
|
||||
}
|
||||
|
||||
@@ -45,6 +45,7 @@ import sonia.scm.cache.CacheManager;
|
||||
import sonia.scm.repository.BrowserResult;
|
||||
import sonia.scm.repository.PreProcessorUtil;
|
||||
import sonia.scm.repository.Repository;
|
||||
import sonia.scm.repository.RepositoryCacheKey;
|
||||
import sonia.scm.repository.RepositoryException;
|
||||
import sonia.scm.repository.spi.BrowseCommand;
|
||||
import sonia.scm.repository.spi.BrowseCommandRequest;
|
||||
@@ -66,7 +67,7 @@ import java.io.Serializable;
|
||||
* BrowserResult result = browse.setPath("scm-core")
|
||||
* .setRevision("11aeec7db845")
|
||||
* .getBrowserResult();
|
||||
*
|
||||
*
|
||||
* for ( FileObject fo : result ){
|
||||
* System.out.println( fo.getPath() );
|
||||
* }
|
||||
@@ -257,7 +258,7 @@ public final class BrowseCommandBuilder
|
||||
* @version Enter version here..., 12/06/05
|
||||
* @author Enter your name here...
|
||||
*/
|
||||
static class CacheKey implements Serializable
|
||||
static class CacheKey implements RepositoryCacheKey, Serializable
|
||||
{
|
||||
|
||||
/**
|
||||
@@ -322,7 +323,8 @@ public final class BrowseCommandBuilder
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
String getRepositoryId()
|
||||
@Override
|
||||
public String getRepositoryId()
|
||||
{
|
||||
return repositoryId;
|
||||
}
|
||||
|
||||
@@ -55,6 +55,7 @@ import sonia.scm.repository.spi.LogCommandRequest;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Serializable;
|
||||
import sonia.scm.repository.RepositoryCacheKey;
|
||||
|
||||
/**
|
||||
* LogCommandBuilder is able to show the history of a file in a
|
||||
@@ -396,7 +397,7 @@ public final class LogCommandBuilder
|
||||
* @version Enter version here..., 12/06/05
|
||||
* @author Enter your name here...
|
||||
*/
|
||||
static class CacheKey implements Serializable
|
||||
static class CacheKey implements RepositoryCacheKey, Serializable
|
||||
{
|
||||
|
||||
/**
|
||||
@@ -476,7 +477,8 @@ public final class LogCommandBuilder
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
String getRepositoryId()
|
||||
@Override
|
||||
public String getRepositoryId()
|
||||
{
|
||||
return repositoryId;
|
||||
}
|
||||
|
||||
@@ -55,6 +55,8 @@ import sonia.scm.repository.PermissionUtil;
|
||||
import sonia.scm.repository.PostReceiveRepositoryHook;
|
||||
import sonia.scm.repository.PreProcessorUtil;
|
||||
import sonia.scm.repository.Repository;
|
||||
import sonia.scm.repository.RepositoryCacheKey;
|
||||
import sonia.scm.repository.RepositoryCacheKeyFilter;
|
||||
import sonia.scm.repository.RepositoryHookEvent;
|
||||
import sonia.scm.repository.RepositoryManager;
|
||||
import sonia.scm.repository.RepositoryNotFoundException;
|
||||
@@ -332,6 +334,7 @@ public final class RepositoryServiceFactory
|
||||
*
|
||||
* @param repositoryId
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
private void clearCaches(final String repositoryId)
|
||||
{
|
||||
if (logger.isDebugEnabled())
|
||||
@@ -339,30 +342,12 @@ public final class RepositoryServiceFactory
|
||||
logger.debug("clear caches for repository id {}", repositoryId);
|
||||
}
|
||||
|
||||
blameCache.removeAll(new Filter<BlameCommandBuilder.CacheKey>()
|
||||
{
|
||||
@Override
|
||||
public boolean accept(BlameCommandBuilder.CacheKey item)
|
||||
{
|
||||
return repositoryId.equals(item.getRepositoryId());
|
||||
}
|
||||
});
|
||||
browseCache.removeAll(new Filter<BrowseCommandBuilder.CacheKey>()
|
||||
{
|
||||
@Override
|
||||
public boolean accept(BrowseCommandBuilder.CacheKey item)
|
||||
{
|
||||
return repositoryId.equals(item.getRepositoryId());
|
||||
}
|
||||
});
|
||||
logCache.removeAll(new Filter<LogCommandBuilder.CacheKey>()
|
||||
{
|
||||
@Override
|
||||
public boolean accept(LogCommandBuilder.CacheKey item)
|
||||
{
|
||||
return repositoryId.equals(item.getRepositoryId());
|
||||
}
|
||||
});
|
||||
RepositoryCacheKeyFilter filter =
|
||||
new RepositoryCacheKeyFilter(repositoryId);
|
||||
|
||||
blameCache.removeAll(filter);
|
||||
browseCache.removeAll(filter);
|
||||
logCache.removeAll(filter);
|
||||
}
|
||||
|
||||
//~--- fields -------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user