Skip to content

Commit e3101c0

Browse files
committed
1311 Multi-thread import folders crawling
1 parent 5dac4e7 commit e3101c0

File tree

3 files changed

+110
-6
lines changed

3 files changed

+110
-6
lines changed

logicaldoc-core/src/main/java/com/logicaldoc/core/searchengine/IndexerTask.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
import com.logicaldoc.core.document.Document;
2626
import com.logicaldoc.core.document.DocumentDAO;
2727
import com.logicaldoc.core.document.DocumentHistory;
28-
import com.logicaldoc.core.document.IndexingStatus;
2928
import com.logicaldoc.core.document.DocumentManager;
3029
import com.logicaldoc.core.document.DocumentStatus;
30+
import com.logicaldoc.core.document.IndexingStatus;
3131
import com.logicaldoc.core.security.Tenant;
3232
import com.logicaldoc.core.security.TenantDAO;
3333
import com.logicaldoc.core.task.Task;
@@ -152,7 +152,8 @@ protected void runTask() throws TaskException {
152152
log.info("Distribute the indexing among {} threads", threadsTotal);
153153

154154
// Divide the docs in groups of N
155-
Collection<List<Long>> partitions = CollectionUtil.partition(docIds, threadsTotal);
155+
Collection<List<Long>> partitions = CollectionUtil.partition(docIds,
156+
(int) Math.ceil((double) docIds.size() / (double) threadsTotal));
156157

157158
startIndexerThreads(threadsTotal);
158159
List<IndexerThread> threads = new ArrayList<>();
@@ -298,10 +299,10 @@ else if ("smallestfirst".equals(sorting))
298299
if (StringUtils.isNotEmpty(sortingCustom))
299300
sorting = sortingCustom;
300301

301-
String where = PersistentObjectDAO.ENTITY + ".deleted = 0 and (" + PersistentObjectDAO.ENTITY + ".indexingStatus = "
302-
+ IndexingStatus.TO_INDEX.ordinal() + " or " + PersistentObjectDAO.ENTITY + ".indexingStatus = "
303-
+ IndexingStatus.TO_INDEX_METADATA.ordinal() + ") and not " + PersistentObjectDAO.ENTITY + ".status = "
304-
+ DocumentStatus.ARCHIVED.ordinal();
302+
String where = PersistentObjectDAO.ENTITY + ".deleted = 0 and (" + PersistentObjectDAO.ENTITY
303+
+ ".indexingStatus = " + IndexingStatus.TO_INDEX.ordinal() + " or " + PersistentObjectDAO.ENTITY
304+
+ ".indexingStatus = " + IndexingStatus.TO_INDEX_METADATA.ordinal() + ") and not "
305+
+ PersistentObjectDAO.ENTITY + ".status = " + DocumentStatus.ARCHIVED.ordinal();
305306

306307
return new String[] { where, sorting };
307308
}
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
package com.logicaldoc.gui.frontend.client.impex.folders;
2+
3+
import java.util.ArrayList;
4+
import java.util.Arrays;
5+
import java.util.List;
6+
7+
import com.logicaldoc.gui.common.client.DefaultAsyncCallback;
8+
import com.logicaldoc.gui.common.client.Session;
9+
import com.logicaldoc.gui.common.client.beans.GUIParameter;
10+
import com.logicaldoc.gui.common.client.i18n.I18N;
11+
import com.logicaldoc.gui.common.client.util.ItemFactory;
12+
import com.logicaldoc.gui.common.client.util.Util;
13+
import com.logicaldoc.gui.frontend.client.services.SettingService;
14+
import com.smartgwt.client.types.HeaderControls;
15+
import com.smartgwt.client.types.TitleOrientation;
16+
import com.smartgwt.client.widgets.Window;
17+
import com.smartgwt.client.widgets.form.DynamicForm;
18+
import com.smartgwt.client.widgets.form.fields.ButtonItem;
19+
import com.smartgwt.client.widgets.form.fields.SpinnerItem;
20+
21+
/**
22+
* This popup window is used to input data and obtain a prediction from the AI
23+
* model.
24+
*
25+
* @author Marco Meschieri - LogicalDOC
26+
* @since 9.2
27+
*/
28+
public class ImportFolderSettings extends Window {
29+
30+
private static final String THREADS_SETTING = "threadpool.ImportFolderCrawler.max";
31+
32+
private DynamicForm form = new DynamicForm();
33+
34+
public ImportFolderSettings() {
35+
setHeaderControls(HeaderControls.HEADER_LABEL, HeaderControls.CLOSE_BUTTON);
36+
37+
setTitle(I18N.message("settings"));
38+
setAutoSize(true);
39+
setCanDragResize(true);
40+
setIsModal(true);
41+
setShowModalMask(true);
42+
centerInPage();
43+
44+
SettingService.Instance.get().loadSettingsByNames(Arrays.asList(new String[] { THREADS_SETTING }),
45+
new DefaultAsyncCallback<>() {
46+
47+
@Override
48+
public void onSuccess(List<GUIParameter> params) {
49+
init(params);
50+
}
51+
});
52+
}
53+
54+
private void init(List<GUIParameter> params) {
55+
ButtonItem save = new ButtonItem();
56+
save.setTitle(I18N.message("save"));
57+
save.setAutoFit(true);
58+
save.setStartRow(true);
59+
save.addClickHandler(event -> onSave());
60+
61+
SpinnerItem threads = ItemFactory.newSpinnerItem("threads",
62+
Integer.parseInt(Util.getValue(THREADS_SETTING, params)));
63+
threads.setRequired(true);
64+
threads.setMin(1);
65+
threads.setStep(1);
66+
threads.setVisible(Session.get().isDefaultTenant());
67+
68+
form.setNumCols(1);
69+
form.setTitleOrientation(TitleOrientation.TOP);
70+
form.setFields(threads, save);
71+
72+
addItem(form);
73+
}
74+
75+
private void onSave() {
76+
if (!form.validate())
77+
return;
78+
79+
List<GUIParameter> params = new ArrayList<>();
80+
params.add(new GUIParameter(THREADS_SETTING, form.getValueAsString("threads")));
81+
SettingService.Instance.get().saveSettings(params, new DefaultAsyncCallback<>());
82+
83+
destroy();
84+
}
85+
86+
@Override
87+
public boolean equals(Object other) {
88+
return super.equals(other);
89+
}
90+
91+
@Override
92+
public int hashCode() {
93+
return super.hashCode();
94+
}
95+
}

logicaldoc-gui/src/main/java/com/logicaldoc/gui/frontend/client/impex/folders/ImportFoldersPanel.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,14 @@ public void onDraw() {
121121
if (Feature.enabled(Feature.IMPORT_LOCAL_FOLDERS) || Feature.enabled(Feature.IMPORT_REMOTE_FOLDERS))
122122
toolStrip.addButton(addImportFolder);
123123

124+
toolStrip.addSeparator();
125+
126+
ToolStripButton settings = new ToolStripButton();
127+
settings.setTitle(I18N.message("settings"));
128+
toolStrip.addButton(settings);
129+
settings.addClickHandler(click -> new ImportFolderSettings().show());
130+
131+
124132
list.addCellContextClickHandler(click -> {
125133
showContextMenu();
126134
click.cancel();

0 commit comments

Comments
 (0)