Skip to content
This repository has been archived by the owner on Sep 12, 2018. It is now read-only.

Commit

Permalink
Merge branch 'issue-2095' of dlab/hive
Browse files Browse the repository at this point in the history
from pull-request 1465

* refs/heads/issue-2095:
  Removed LabelSearchUtil
  Enhanced performance for searching with label.

Reviewed-by: 이응준 <eungjun.yi@navercorp.com>
  • Loading branch information
이응준 committed Feb 10, 2015
2 parents 0a94499 + bee5790 commit 1e9e200
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 98 deletions.
2 changes: 1 addition & 1 deletion app/controllers/IssueApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public static Result issues(String ownerName, String projectName, String state,
Form<models.support.SearchCondition> issueParamForm = new Form<>(models.support.SearchCondition.class);
models.support.SearchCondition searchCondition = issueParamForm.bindFromRequest().get();
searchCondition.pageNum = pageNum - 1;
searchCondition.labelIds.addAll(LabelSearchUtil.getLabelIds(request()));
searchCondition.labelIds.addAll(LabelApp.getLabelIds(request()));
searchCondition.labelIds.remove(null);

// determine pjax or json when requested with XHR
Expand Down
16 changes: 16 additions & 0 deletions app/controllers/LabelApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,15 @@
import com.avaje.ebean.SqlRow;
import controllers.annotation.AnonymousCheck;
import models.Label;
import org.apache.commons.lang3.StringUtils;
import play.mvc.Controller;
import play.mvc.Http;
import play.mvc.Result;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import static com.avaje.ebean.Expr.icontains;
import static play.libs.Json.toJson;
Expand Down Expand Up @@ -113,4 +116,17 @@ public static Result categories(String query, Integer limit) {

return ok(toJson(categories));
}

public static Set<Long> getLabelIds(final Http.Request request) {
Set<Long> set = new HashSet<>();
String[] labelIds = request.queryString().get("labelIds");
if (labelIds != null) {
for (String labelId : labelIds) {
if(!StringUtils.isEmpty(labelId)) {
set.add(Long.valueOf(labelId));
}
}
}
return set;
}
}
4 changes: 2 additions & 2 deletions app/controllers/ProjectApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -938,9 +938,9 @@ public static Result projects(String query, int pageNum) {
private static Result getPagingProjects(String query, int pageNum) {
ExpressionList<Project> el = createProjectSearchExpressionList(query);

Set<Long> labelIds = LabelSearchUtil.getLabelIds(request());
Set<Long> labelIds = LabelApp.getLabelIds(request());
if (CollectionUtils.isNotEmpty(labelIds)) {
el.add(LabelSearchUtil.createLabelSearchExpression(el.query(), labelIds));
el.in("labels.id", labelIds);
}

el.orderBy("createdDate desc");
Expand Down
7 changes: 3 additions & 4 deletions app/models/support/SearchCondition.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,12 @@
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateUtils;
import play.data.format.Formats;
import utils.LabelSearchUtil;

import javax.persistence.Transient;
import java.text.SimpleDateFormat;
import java.util.*;

import static models.enumeration.ResourceType.*;
import static models.enumeration.ResourceType.ISSUE_COMMENT;
import static models.enumeration.ResourceType.ISSUE_POST;

public class SearchCondition extends AbstractPostingApp.SearchCondition {
public String state;
Expand Down Expand Up @@ -307,7 +306,7 @@ public ExpressionList<Issue> asExpressionList(Project project) {
}

if (CollectionUtils.isNotEmpty(labelIds)) {
el.add(LabelSearchUtil.createLabelSearchExpression(el.query(), labelIds));
el.in("labels.id", labelIds);
}

if (StringUtils.isNotBlank(orderBy)) {
Expand Down
91 changes: 0 additions & 91 deletions app/utils/LabelSearchUtil.java

This file was deleted.

0 comments on commit 1e9e200

Please sign in to comment.