Permalink
Browse files

don't commit index writer all too often when indexing multiple pages …

…at once
  • Loading branch information...
1 parent dcaa643 commit 6bf038dc8bdf3717368d956c8fd481f3a1da650b @blizzy78 committed Aug 17, 2012
Showing with 17 additions and 4 deletions.
  1. +17 −4 de.blizzy.documentr/src/main/java/de/blizzy/documentr/search/PageIndex.java
View
21 de.blizzy.documentr/src/main/java/de/blizzy/documentr/search/PageIndex.java
@@ -272,7 +272,7 @@ private void addPage(final String projectName, final String branchName, final St
@Override
public void run() {
try {
- addPageAsync(projectName, branchName, path);
+ addPageAsync(projectName, branchName, path, true);
} catch (IOException e) {
// TODO: log exception
} catch (RuntimeException e) {
@@ -294,22 +294,32 @@ private void addPages(final String projectName, final String branchName) {
Runnable runnable = new Runnable() {
@Override
public void run() {
+ boolean dirty = false;
try {
List<String> paths = pageStore.listAllPagePaths(projectName, branchName);
for (String path : paths) {
- addPageAsync(projectName, branchName, path);
+ addPageAsync(projectName, branchName, path, false);
+ dirty = true;
}
} catch (IOException e) {
// TODO: log exception
} catch (RuntimeException e) {
// TODO: log exception
+ } finally {
+ if (dirty) {
+ try {
+ writer.commit();
+ } catch (IOException e) {
+ // TODO: log exception
+ }
+ }
}
}
};
threadPool.submit(runnable);
}
- private void addPageAsync(String projectName, String branchName, String path) throws IOException {
+ private void addPageAsync(String projectName, String branchName, String path, boolean commit) throws IOException {
Page page = pageStore.getPage(projectName, branchName, path, true);
String fullPath = projectName + "/" + branchName + "/" + Util.toURLPagePath(path); //$NON-NLS-1$ //$NON-NLS-2$
@@ -346,7 +356,10 @@ private void addPageAsync(String projectName, String branchName, String path) th
}
writer.updateDocument(new Term(FULL_PATH, fullPath), doc);
- writer.commit();
+
+ if (commit) {
+ writer.commit();
+ }
}
private String removeHtmlTags(String html) {

0 comments on commit 6bf038d

Please sign in to comment.