private final DbClient dbClient;
public ActivityIndexer(DbClient dbClient, EsClient esClient) {
- super(esClient, 0L, ActivityIndexDefinition.INDEX, ActivityIndexDefinition.TYPE);
+ super(esClient, 0L, ActivityIndexDefinition.INDEX, ActivityIndexDefinition.TYPE, ActivityIndexDefinition.FIELD_CREATED_AT);
this.dbClient = dbClient;
}
public abstract class BaseIndexer implements ServerComponent, Startable {
private final ThreadPoolExecutor executor;
- private final String indexName, typeName;
+ private final String indexName, typeName, dateFieldName;
protected final EsClient esClient;
private volatile long lastUpdatedAt = 0L;
*/
private boolean enabled = false;
- protected BaseIndexer(EsClient client, long threadKeepAliveSeconds, String indexName, String typeName) {
+ protected BaseIndexer(EsClient client, long threadKeepAliveSeconds, String indexName, String typeName,
+ String dateFieldName) {
this.indexName = indexName;
this.typeName = typeName;
+ this.dateFieldName = dateFieldName;
this.esClient = client;
this.executor = new ThreadPoolExecutor(0, 1,
threadKeepAliveSeconds, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>());
@Override
public void start() {
- lastUpdatedAt = esClient.getLastUpdatedAt(indexName, typeName);
+ lastUpdatedAt = esClient.getMaxFieldValue(indexName, typeName, dateFieldName);
}
@Override
return new ProxyClearCacheRequestBuilder(client).setIndices(indices);
}
- public long getLastUpdatedAt(String indexName, String typeName) {
+ public long getMaxFieldValue(String indexName, String typeName, String fieldName) {
SearchRequestBuilder request = prepareSearch(indexName)
.setTypes(typeName)
.setQuery(QueryBuilders.matchAllQuery())
.setSize(0)
- .addAggregation(AggregationBuilders.max("latest").field("updatedAt"));
+ .addAggregation(AggregationBuilders.max("latest").field(fieldName));
Max max = request.get().getAggregations().get("latest");
return (long) max.getValue();
private final DbClient dbClient;
public IssueAuthorizationIndexer(DbClient dbClient, EsClient esClient) {
- super(esClient, 0L, IssueIndexDefinition.INDEX, IssueIndexDefinition.TYPE_AUTHORIZATION);
+ super(esClient, 0L, IssueIndexDefinition.INDEX, IssueIndexDefinition.TYPE_AUTHORIZATION, IssueIndexDefinition.FIELD_ISSUE_TECHNICAL_UPDATED_AT);
this.dbClient = dbClient;
}
private final DbClient dbClient;
public IssueIndexer(DbClient dbClient, EsClient esClient) {
- super(esClient, 300, IssueIndexDefinition.INDEX, IssueIndexDefinition.TYPE_ISSUE);
+ super(esClient, 300, IssueIndexDefinition.INDEX, IssueIndexDefinition.TYPE_ISSUE, IssueIndexDefinition.FIELD_ISSUE_TECHNICAL_UPDATED_AT);
this.dbClient = dbClient;
}
import com.google.common.collect.ImmutableList;
import org.sonar.server.search.BaseDoc;
-import org.sonar.server.search.BaseNormalizer;
import org.sonar.server.search.IndexUtils;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
-
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
}
public Date updateDate() {
- return getFieldAsDate(BaseNormalizer.UPDATED_AT_FIELD);
+ return getFieldAsDate(SourceLineIndexDefinition.FIELD_UPDATED_AT);
}
public SourceLineDoc setUpdateDate(@Nullable Date updatedAt) {
- setField(BaseNormalizer.UPDATED_AT_FIELD, updatedAt);
+ setField(SourceLineIndexDefinition.FIELD_UPDATED_AT, updatedAt);
return this;
}
import org.sonar.process.ProcessConstants;
import org.sonar.server.es.IndexDefinition;
import org.sonar.server.es.NewIndex;
-import org.sonar.server.search.BaseNormalizer;
public class SourceLineIndexDefinition implements IndexDefinition {
public static final String FIELD_OVERALL_COVERED_CONDITIONS = "overallCoveredConditions";
public static final String FIELD_SYMBOLS = "symbols";
public static final String FIELD_DUPLICATIONS = "duplications";
+ public static final String FIELD_UPDATED_AT = "updatedAt";
public static final String INDEX = "sourcelines";
sourceLineMapping.createIntegerField(FIELD_OVERALL_COVERED_CONDITIONS);
sourceLineMapping.stringFieldBuilder(FIELD_SYMBOLS).disableSearch().build();
sourceLineMapping.createShortField(FIELD_DUPLICATIONS);
- sourceLineMapping.createDateTimeField(BaseNormalizer.UPDATED_AT_FIELD);
+ sourceLineMapping.createDateTimeField(FIELD_UPDATED_AT);
}
}
private final DbClient dbClient;
public SourceLineIndexer(DbClient dbClient, EsClient esClient) {
- super(esClient, 0L, SourceLineIndexDefinition.INDEX, SourceLineIndexDefinition.TYPE);
+ super(esClient, 0L, SourceLineIndexDefinition.INDEX, SourceLineIndexDefinition.TYPE, SourceLineIndexDefinition.FIELD_UPDATED_AT);
this.dbClient = dbClient;
}
private final DbClient dbClient;
public UserIndexer(DbClient dbClient, EsClient esClient) {
- super(esClient, 300, UserIndexDefinition.INDEX, UserIndexDefinition.TYPE_USER);
+ super(esClient, 300, UserIndexDefinition.INDEX, UserIndexDefinition.TYPE_USER, UserIndexDefinition.FIELD_UPDATED_AT);
this.dbClient = dbClient;
}
private final EsClient esClient;
public ViewIndexer(DbClient dbClient, EsClient esClient) {
- super(esClient, 300, ViewIndexDefinition.INDEX, ViewIndexDefinition.TYPE_VIEW);
+ super(esClient, 300, ViewIndexDefinition.INDEX, ViewIndexDefinition.TYPE_VIEW, "updatedAt");
this.dbClient = dbClient;
this.esClient = esClient;
}
*/
package org.sonar.server.issue;
-import com.google.common.collect.*;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Iterators;
+import com.google.common.collect.Multiset;
+import com.google.common.collect.Sets;
import org.junit.After;
import org.junit.Before;
import org.junit.ClassRule;
import org.sonar.server.permission.PermissionChange;
import org.sonar.server.rule.RuleTesting;
import org.sonar.server.rule.db.RuleDao;
-import org.sonar.server.search.BaseNormalizer;
import org.sonar.server.source.index.SourceLineDoc;
import org.sonar.server.source.index.SourceLineIndexer;
import org.sonar.server.source.index.SourceLineResultSetIterator;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.entry;
import static org.junit.Assert.fail;
-import static org.sonar.server.source.index.SourceLineIndexDefinition.FIELD_FILE_UUID;
-import static org.sonar.server.source.index.SourceLineIndexDefinition.FIELD_LINE;
-import static org.sonar.server.source.index.SourceLineIndexDefinition.FIELD_PROJECT_UUID;
-import static org.sonar.server.source.index.SourceLineIndexDefinition.FIELD_SCM_AUTHOR;
+import static org.sonar.server.source.index.SourceLineIndexDefinition.*;
public class IssueServiceMediumTest {
.put(FIELD_PROJECT_UUID, file.projectUuid())
.put(FIELD_FILE_UUID, file.uuid())
.put(FIELD_LINE, line)
- .put(BaseNormalizer.UPDATED_AT_FIELD, new Date())
+ .put(FIELD_UPDATED_AT, new Date())
.put(FIELD_SCM_AUTHOR, scmAuthor)
.build());
SourceLineResultSetIterator.SourceFile sourceFile = new SourceLineResultSetIterator.SourceFile(file.uuid(), System.currentTimeMillis());
import org.sonar.core.persistence.DbTester;
import org.sonar.server.db.DbClient;
import org.sonar.server.es.EsTester;
-import org.sonar.server.search.BaseNormalizer;
import org.sonar.server.source.db.FileSourceTesting;
import org.sonar.test.DbTests;
import org.sonar.test.TestUtils;
.put(FIELD_SCM_AUTHOR, "polop")
.put(FIELD_SOURCE, "package org.sonar.server.source;")
.put(FIELD_DUPLICATIONS, duplications)
- .put(BaseNormalizer.UPDATED_AT_FIELD, new Date())
+ .put(FIELD_UPDATED_AT, new Date())
.build());
SourceLineResultSetIterator.SourceFile file = new SourceLineResultSetIterator.SourceFile("efgh", System.currentTimeMillis());
file.addLine(line1);
.put(FIELD_OVERALL_LINE_HITS, bigValue)
.put(FIELD_OVERALL_CONDITIONS, bigValue)
.put(FIELD_OVERALL_COVERED_CONDITIONS, bigValue)
- .put(BaseNormalizer.UPDATED_AT_FIELD, new Date())
+ .put(FIELD_UPDATED_AT, new Date())
.build());
SourceLineResultSetIterator.SourceFile file = new SourceLineResultSetIterator.SourceFile("efgh", System.currentTimeMillis());
file.addLine(line1);