Skip to content

Commit

Permalink
- Code Smells and Cache Search improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
alegauss committed Nov 27, 2024
1 parent 26116af commit a0a8029
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,18 @@ public ResponseEntity<TurSNSiteSearchBean> turSNSiteSearchSelectGet(
HttpServletRequest request) {
Locale locale = LocaleUtils.toLocale(localeRequest);
if (existsByTurSNSiteAndLanguage(siteName, locale)) {
TurSEFilterQueryParameters turSEFilterQueryParameters = new TurSEFilterQueryParameters(filterQueriesDefault,
filterQueriesAnd, filterQueriesOr, fqOperator);
TurSEParameters turSEParameters = new TurSEParameters(q, turSEFilterQueryParameters, currentPage, sort,
rows, group, autoCorrectionDisabled);
URI uri = TurSNUtils.requestToURI(request);
TurSNSiteSearchContext turSNSiteSearchContext = new TurSNSiteSearchContext(siteName, turSEParameters, locale,
uri);
if (searchCacheEnabled) {
return new ResponseEntity<>(turSNSiteSearchCachedAPI.searchCached(siteName, q, currentPage,
filterQueriesDefault, filterQueriesAnd, filterQueriesOr, fqOperator, sort, rows, group,
autoCorrectionDisabled, request, locale), HttpStatus.OK);
}
else {
return new ResponseEntity<>(turSNSearchProcess.search(new TurSNSiteSearchContext(siteName,
new TurSEParameters(q, new TurSEFilterQueryParameters(filterQueriesDefault, filterQueriesAnd,
filterQueriesOr, fqOperator), currentPage, sort, rows, group, autoCorrectionDisabled), locale,
TurSNUtils.requestToURI(request))), HttpStatus.OK);
String cacheKey = "%s_%s".formatted(siteName, request.getQueryString());
return new ResponseEntity<>(turSNSiteSearchCachedAPI.searchCached(cacheKey, turSNSiteSearchContext), HttpStatus.OK);
} else {
return new ResponseEntity<>(turSNSearchProcess.search(turSNSiteSearchContext), HttpStatus.OK);
}
} else {
return ResponseEntity.status(HttpStatus.NOT_FOUND).build();
Expand Down Expand Up @@ -180,7 +182,8 @@ public ResponseEntity<List<String>> turSNSiteSearchLatestImpersonate(
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).build();
}

private String isLatestImpersonate(Optional<TurSNSearchLatestRequestBean> turSNSearchLatestRequestBean, Principal principal) {
private String isLatestImpersonate(Optional<TurSNSearchLatestRequestBean> turSNSearchLatestRequestBean,
Principal principal) {
if (turSNSearchLatestRequestBean.isPresent() && turSNSearchLatestRequestBean.get().getUserId() != null) {
return turSNSearchLatestRequestBean.get().getUserId();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.net.URI;
import java.util.List;
import java.util.Locale;
import java.util.concurrent.TimeUnit;
Expand All @@ -50,22 +51,9 @@ public void cleanSearchCache() {
log.info("Cleaning Search API");
}

@Cacheable(value = "searchAPI", key = "#request.queryString")
public TurSNSiteSearchBean searchCached(String siteName, String q, Integer currentPage,
List<String> filterQueriesDefault,
List<String> filterQueriesAnd,
List<String> filterQueriesOr,
TurSNFilterQueryOperator fqOperator,
String sort,
Integer rows,
String group,
Integer autoCorrectionDisabled,
HttpServletRequest
request,
Locale locale) {
return turSNSearchProcess.search(new TurSNSiteSearchContext(siteName,
new TurSEParameters(q, new TurSEFilterQueryParameters(filterQueriesDefault, filterQueriesAnd,
filterQueriesOr, fqOperator), currentPage, sort, rows, group, autoCorrectionDisabled), locale,
TurSNUtils.requestToURI(request)));
@Cacheable(value = "searchAPI", key = "#cacheKey")
public TurSNSiteSearchBean searchCached(String cacheKey,
TurSNSiteSearchContext turSNSiteSearchContext) {
return turSNSearchProcess.search(turSNSiteSearchContext);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
package com.viglet.turing.persistence.repository.sn.ranking;

import com.viglet.turing.persistence.model.sn.TurSNSite;
import com.viglet.turing.persistence.model.sn.ranking.TurSNRankingCondition;
import com.viglet.turing.persistence.model.sn.ranking.TurSNRankingExpression;
import org.jetbrains.annotations.NotNull;
import org.springframework.cache.annotation.CacheEvict;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import lombok.Setter;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ public TurSEParameters(String query, TurSEFilterQueryParameters filterQueries,
}
public TurSEParameters(String query, TurSEFilterQueryParameters filterQueries,
Integer currentPage, String sort, Integer rows,
String group, Integer autoCorrectionDisabled, TurSNSitePostParamsBean turSNSitePostParamsBean) {
String group, Integer autoCorrectionDisabled,
TurSNSitePostParamsBean turSNSitePostParamsBean) {
super();
this.query = query;
this.filterQueries = filterQueries;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ public class TurSNSiteSearchDocumentBean implements Serializable {
private String source;
private boolean elevate;
private List<TurSNSiteSearchDocumentMetadataBean> metadata;
private Map<String,Object> fields;
private transient Map<String,Object> fields;

}

0 comments on commit a0a8029

Please sign in to comment.