fix #1180 remove session cache from ThumbnailManager
This commit is contained in:
parent
3e486e531e
commit
6d5f5fe77a
8 changed files with 34 additions and 85 deletions
|
@ -32,14 +32,11 @@
|
|||
<div class="body">
|
||||
<div>
|
||||
<div class="thumbnailBox media-left hidden-xs-down">
|
||||
<a class="link" href="{{url}}" data-uri="{{url}}" data-id="b4acd0fd3e244f57a1d08580f5ac6ee6"
|
||||
data-order="1"
|
||||
>
|
||||
<img src="{{../context_path}}/images/blank.png"
|
||||
data-src="{{../context_path}}/thumbnail/?docId={{doc_id}}&queryId={{../query_id}}" class="thumbnail"
|
||||
>
|
||||
</a>
|
||||
</div>
|
||||
<a class="link" href="{{url}}" data-uri="{{url}}" data-id="{{doc_id}}" data-order="1">
|
||||
<img src="{{../context_path}}/images/blank.png"
|
||||
data-src="{{../context_path}}/thumbnail/?docId={{doc_id}}&queryId={{../query_id}}" class="thumbnail">
|
||||
</a>
|
||||
</div>
|
||||
<div class="media-body description">
|
||||
{{{content_description}}}
|
||||
</div>
|
||||
|
|
|
@ -268,8 +268,6 @@ public class Constants extends CoreLibConstants {
|
|||
|
||||
public static final String RESULT_DOC_ID_CACHE = "resultDocIds";
|
||||
|
||||
public static final String SCREEN_SHOT_PATH_CACHE = "thumbnailPaths";
|
||||
|
||||
public static final String CRAWLING_INFO_SYSTEM_NAME = "system";
|
||||
|
||||
// view parameters
|
||||
|
|
|
@ -47,7 +47,6 @@ import org.codelibs.fess.helper.RelatedQueryHelper;
|
|||
import org.codelibs.fess.helper.SystemHelper;
|
||||
import org.codelibs.fess.helper.UserInfoHelper;
|
||||
import org.codelibs.fess.mylasta.direction.FessConfig;
|
||||
import org.codelibs.fess.thumbnail.ThumbnailManager;
|
||||
import org.codelibs.fess.util.ComponentUtil;
|
||||
import org.codelibs.fess.util.DocumentUtil;
|
||||
import org.codelibs.fess.util.FacetResponse;
|
||||
|
@ -286,13 +285,6 @@ public class JsonApiManager extends BaseJsonApiManager {
|
|||
buf.append(']');
|
||||
}
|
||||
}
|
||||
|
||||
if (fessConfig.isThumbnailEnabled()) {
|
||||
final UserInfoHelper userInfoHelper = ComponentUtil.getComponent(UserInfoHelper.class);
|
||||
final ThumbnailManager thumbnailManager = ComponentUtil.getComponent(ThumbnailManager.class);
|
||||
userInfoHelper.storeQueryId(queryId, documentItems);
|
||||
thumbnailManager.storeRequest(queryId, documentItems);
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
status = 1;
|
||||
err = e;
|
||||
|
|
|
@ -87,7 +87,6 @@ public class SearchService {
|
|||
final long requestedTime = systemHelper.getCurrentTimeAsLong();
|
||||
|
||||
final long startTime = System.currentTimeMillis();
|
||||
final boolean searchLogSupport = fessConfig.isSearchLog();
|
||||
|
||||
final String query =
|
||||
QueryStringBuilder.query(params.getQuery()).extraQueries(params.getExtraQueries()).fields(params.getFields()).build();
|
||||
|
@ -157,10 +156,16 @@ public class SearchService {
|
|||
data.setQueryId(queryId);
|
||||
|
||||
// search log
|
||||
if (searchLogSupport) {
|
||||
if (fessConfig.isSearchLog()) {
|
||||
ComponentUtil.getSearchLogHelper().addSearchLog(params, DfTypeUtil.toLocalDateTime(requestedTime), queryId, query, pageStart,
|
||||
pageSize, queryResponseList);
|
||||
}
|
||||
|
||||
// favorite
|
||||
if (fessConfig.isUserFavorite()) {
|
||||
ComponentUtil.getUserInfoHelper().storeQueryId(queryId, documentItems);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public int deleteByQuery(final HttpServletRequest request, final SearchRequestParams params) {
|
||||
|
|
|
@ -134,29 +134,21 @@ public class SearchAction extends FessSearchAction {
|
|||
request.setAttribute(Constants.REQUEST_QUERIES, form.q);
|
||||
final WebRenderData renderData = new WebRenderData();
|
||||
searchService.search(form, renderData, getUserBean());
|
||||
return asHtml(virtualHost(path_SearchJsp)).renderWith(data -> {
|
||||
renderData.register(data);
|
||||
// favorite or thumbnail
|
||||
if (favoriteSupport || thumbnailSupport) {
|
||||
final String queryId = renderData.getQueryId();
|
||||
final List<Map<String, Object>> documentItems = renderData.getDocumentItems();
|
||||
userInfoHelper.storeQueryId(queryId, documentItems);
|
||||
if (thumbnailSupport) {
|
||||
thumbnailManager.storeRequest(queryId, documentItems);
|
||||
return asHtml(virtualHost(path_SearchJsp)).renderWith(
|
||||
data -> {
|
||||
renderData.register(data);
|
||||
RenderDataUtil.register(data, "displayQuery",
|
||||
getDisplayQuery(form, labelTypeHelper.getLabelTypeItemList(SearchRequestType.SEARCH)));
|
||||
createPagingQuery(form);
|
||||
final String relatedContent = relatedContentHelper.getRelatedContent(form.getQuery());
|
||||
if (StringUtil.isNotBlank(relatedContent)) {
|
||||
RenderDataUtil.register(data, "relatedContent", relatedContent);
|
||||
}
|
||||
}
|
||||
RenderDataUtil.register(data, "displayQuery",
|
||||
getDisplayQuery(form, labelTypeHelper.getLabelTypeItemList(SearchRequestType.SEARCH)));
|
||||
createPagingQuery(form);
|
||||
final String relatedContent = relatedContentHelper.getRelatedContent(form.getQuery());
|
||||
if (StringUtil.isNotBlank(relatedContent)) {
|
||||
RenderDataUtil.register(data, "relatedContent", relatedContent);
|
||||
}
|
||||
final String[] relatedQueries = relatedQueryHelper.getRelatedQueries(form.getQuery());
|
||||
if (relatedQueries.length > 0) {
|
||||
RenderDataUtil.register(data, "relatedQueries", relatedQueries);
|
||||
}
|
||||
});
|
||||
final String[] relatedQueries = relatedQueryHelper.getRelatedQueries(form.getQuery());
|
||||
if (relatedQueries.length > 0) {
|
||||
RenderDataUtil.register(data, "relatedQueries", relatedQueries);
|
||||
}
|
||||
});
|
||||
} catch (final InvalidQueryException e) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug(e.getMessage(), e);
|
||||
|
|
|
@ -53,13 +53,13 @@ public class ThumbnailAction extends FessSearchAction {
|
|||
|
||||
final Map<String, Object> doc =
|
||||
searchService.getDocumentByDocId(form.docId, queryHelper.getResponseFields(), getUserBean()).orElse(null);
|
||||
final String url = DocumentUtil.getValue(doc, fessConfig.getIndexFieldUrl(), String.class);
|
||||
final String url = DocumentUtil.getValue(doc, fessConfig.getIndexFieldThumbnail(), String.class);
|
||||
if (StringUtil.isBlank(form.queryId) || StringUtil.isBlank(url) || !thumbnailSupport) {
|
||||
// 404
|
||||
throw responseManager.new404("Thumbnail for " + form.docId + " is not found.");
|
||||
}
|
||||
|
||||
final File thumbnailFile = thumbnailManager.getThumbnailFile(form.queryId, form.docId);
|
||||
final File thumbnailFile = thumbnailManager.getThumbnailFile(doc);
|
||||
if (thumbnailFile == null) {
|
||||
// 404
|
||||
thumbnailManager.offer(doc);
|
||||
|
|
|
@ -32,9 +32,7 @@ import java.util.concurrent.TimeUnit;
|
|||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.annotation.PreDestroy;
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
import org.codelibs.core.collection.LruHashMap;
|
||||
import org.codelibs.core.lang.StringUtil;
|
||||
import org.codelibs.core.misc.Tuple3;
|
||||
import org.codelibs.fess.Constants;
|
||||
|
@ -49,7 +47,6 @@ import org.codelibs.fess.util.ComponentUtil;
|
|||
import org.codelibs.fess.util.DocumentUtil;
|
||||
import org.codelibs.fess.util.ResourceUtil;
|
||||
import org.elasticsearch.index.query.QueryBuilders;
|
||||
import org.lastaflute.web.util.LaRequestUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -282,47 +279,17 @@ public class ThumbnailManager {
|
|||
return buf.toString();
|
||||
}
|
||||
|
||||
public void storeRequest(final String queryId, final List<Map<String, Object>> documentItems) {
|
||||
final FessConfig fessConfig = ComponentUtil.getFessConfig();
|
||||
final Map<String, String> dataMap = new HashMap<>(documentItems.size());
|
||||
for (final Map<String, Object> docMap : documentItems) {
|
||||
final String docid = (String) docMap.get(fessConfig.getIndexFieldDocId());
|
||||
final String thumbnailPath = getImageFilename(docMap);
|
||||
if (StringUtil.isNotBlank(docid) && StringUtil.isNotBlank(thumbnailPath)) {
|
||||
dataMap.put(docid, thumbnailPath);
|
||||
}
|
||||
}
|
||||
final Map<String, Map<String, String>> thumbnailPathCache = getThumbnailPathCache(LaRequestUtil.getRequest().getSession());
|
||||
thumbnailPathCache.put(queryId, dataMap);
|
||||
}
|
||||
|
||||
public File getThumbnailFile(final String queryId, final String docId) {
|
||||
final HttpSession session = LaRequestUtil.getRequest().getSession(false);
|
||||
if (session != null) {
|
||||
final Map<String, Map<String, String>> thumbnailPathCache = getThumbnailPathCache(session);
|
||||
final Map<String, String> dataMap = thumbnailPathCache.get(queryId);
|
||||
if (dataMap != null) {
|
||||
final String path = dataMap.get(docId);
|
||||
final File file = new File(baseDir, path);
|
||||
if (file.isFile()) {
|
||||
return file;
|
||||
}
|
||||
public File getThumbnailFile(final Map<String, Object> docMap) {
|
||||
final String thumbnailPath = getImageFilename(docMap);
|
||||
if (StringUtil.isNotBlank(thumbnailPath)) {
|
||||
final File file = new File(baseDir, thumbnailPath);
|
||||
if (file.isFile()) {
|
||||
return file;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private Map<String, Map<String, String>> getThumbnailPathCache(final HttpSession session) {
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Map<String, String>> thumbnailPathCache =
|
||||
(Map<String, Map<String, String>>) session.getAttribute(Constants.SCREEN_SHOT_PATH_CACHE);
|
||||
if (thumbnailPathCache == null) {
|
||||
thumbnailPathCache = new LruHashMap<>(thumbnailPathCacheSize);
|
||||
session.setAttribute(Constants.SCREEN_SHOT_PATH_CACHE, thumbnailPathCache);
|
||||
}
|
||||
return thumbnailPathCache;
|
||||
}
|
||||
|
||||
public void add(final ThumbnailGenerator generator) {
|
||||
if (generator.isAvailable()) {
|
||||
generatorList.add(generator);
|
||||
|
|
|
@ -21,9 +21,7 @@ import java.awt.image.BufferedImage;
|
|||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Iterator;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.imageio.ImageReadParam;
|
||||
|
|
Loading…
Add table
Reference in a new issue