From 3d0494ad6db80843add9bf9d6eac783a691ac5a1 Mon Sep 17 00:00:00 2001 From: James Moger <james.moger@gitblit.com> Date: Fri, 09 Mar 2012 20:45:52 -0500 Subject: [PATCH] More Lucene progress --- src/com/gitblit/LuceneExecutor.java | 52 +++++++++++++++++++++++++++------------------------- 1 files changed, 27 insertions(+), 25 deletions(-) diff --git a/src/com/gitblit/LuceneExecutor.java b/src/com/gitblit/LuceneExecutor.java index b4e5134..4f06b4e 100644 --- a/src/com/gitblit/LuceneExecutor.java +++ b/src/com/gitblit/LuceneExecutor.java @@ -105,26 +105,26 @@ Set<String> processed = new HashSet<String>(); if (!queue.isEmpty()) { // update the repository Lucene index - String repositoryName = null; - while ((repositoryName = queue.poll()) != null) { - if (processed.contains(repositoryName)) { + String name = null; + while ((name = queue.poll()) != null) { + if (processed.contains(name)) { // skipping multi-queued repository continue; } try { - Repository repository = GitBlit.self().getRepository(repositoryName); + Repository repository = GitBlit.self().getRepository(name); if (repository == null) { logger.warn(MessageFormat.format( "Lucene executor could not find repository {0}. Skipping.", - repositoryName)); + name)); continue; } - index(repositoryName, repository); + index(name, repository); repository.close(); - processed.add(repositoryName); + processed.add(name); } catch (Throwable e) { logger.error(MessageFormat.format("Failed to update {0} Lucene index", - repositoryName), e); + name), e); } } } @@ -134,51 +134,53 @@ * Synchronously indexes a repository. This may build a complete index of a * repository or it may update an existing index. * - * @param repositoryName + * @param name * the name of the repository * @param repository * the repository object */ - public void index(String repositoryName, Repository repository) { + public void index(String name, Repository repository) { try { if (JGitUtils.hasCommits(repository)) { if (LuceneUtils.shouldReindex(repository)) { // (re)build the entire index long start = System.currentTimeMillis(); - IndexResult result = LuceneUtils.reindex(repository); - long duration = System.currentTimeMillis() - start; + String msg = "Building {0} Lucene index..."; + logger.info(MessageFormat.format(msg, name)); + IndexResult result = LuceneUtils.reindex(name, repository, true); + float duration = (System.currentTimeMillis() - start)/1000f; if (result.success) { if (result.commitCount > 0) { - String msg = "Built {0} Lucene index from {1} commits in {2} msecs"; - logger.info(MessageFormat.format(msg, repositoryName, - result.commitCount, duration)); + msg = "Built {0} Lucene index from {1} commits and {2} files across {3} branches in {4} secs"; + logger.info(MessageFormat.format(msg, name, + result.commitCount, result.blobCount, result.branchCount, duration)); } } else { - String msg = "Could not build {0} Lucene index!"; - logger.error(MessageFormat.format(msg, repositoryName)); + msg = "Could not build {0} Lucene index!"; + logger.error(MessageFormat.format(msg, name)); } } else { // update the index with latest commits long start = System.currentTimeMillis(); - IndexResult result = LuceneUtils.updateIndex(repository); - long duration = System.currentTimeMillis() - start; + IndexResult result = LuceneUtils.updateIndex(name, repository); + float duration = (System.currentTimeMillis() - start)/1000f; if (result.success) { if (result.commitCount > 0) { - String msg = "Updated {0} Lucene index with {1} commits in {2} msecs"; - logger.info(MessageFormat.format(msg, repositoryName, - result.commitCount, duration)); + String msg = "Updated {0} Lucene index with {1} commits and {2} files across {3} branches in {4} secs"; + logger.info(MessageFormat.format(msg, name, + result.commitCount, result.blobCount, result.branchCount, duration)); } } else { String msg = "Could not update {0} Lucene index!"; - logger.error(MessageFormat.format(msg, repositoryName)); + logger.error(MessageFormat.format(msg, name)); } } } else { logger.info(MessageFormat.format("Skipped Lucene index of empty repository {0}", - repositoryName)); + name)); } } catch (Throwable t) { - logger.error(MessageFormat.format("Lucene indexing failure for {0}", repositoryName), t); + logger.error(MessageFormat.format("Lucene indexing failure for {0}", name), t); } } -- Gitblit v1.9.1