Skip to content

Commit

Permalink
delete component ids from the issues table
Browse files Browse the repository at this point in the history
  • Loading branch information
teryk committed Jan 26, 2015
1 parent 31726f3 commit 341bc8e
Show file tree
Hide file tree
Showing 80 changed files with 695 additions and 664 deletions.
Expand Up @@ -34,7 +34,6 @@
import org.sonar.server.search.IndexClient; import org.sonar.server.search.IndexClient;


import javax.annotation.Nullable; import javax.annotation.Nullable;

import java.util.Date; import java.util.Date;


import static org.sonar.core.purge.PurgeConfiguration.newDefaultPurgeConfiguration; import static org.sonar.core.purge.PurgeConfiguration.newDefaultPurgeConfiguration;
Expand All @@ -50,7 +49,7 @@ public class ProjectCleaner implements ServerComponent {
private final IndexClient indexClient; private final IndexClient indexClient;


public ProjectCleaner(PurgeDao purgeDao, DefaultPeriodCleaner periodCleaner, PurgeProfiler profiler, PurgeListener purgeListener, public ProjectCleaner(PurgeDao purgeDao, DefaultPeriodCleaner periodCleaner, PurgeProfiler profiler, PurgeListener purgeListener,
ProjectSettingsFactory projectSettingsFactory, IndexClient indexClient) { ProjectSettingsFactory projectSettingsFactory, IndexClient indexClient) {
this.purgeDao = purgeDao; this.purgeDao = purgeDao;
this.periodCleaner = periodCleaner; this.periodCleaner = periodCleaner;
this.profiler = profiler; this.profiler = profiler;
Expand All @@ -64,9 +63,9 @@ public ProjectCleaner purge(DbSession session, IdUuidPair idUuidPair) {
profiler.reset(); profiler.reset();


Settings settings = projectSettingsFactory.newProjectSettings(session, idUuidPair.getId()); Settings settings = projectSettingsFactory.newProjectSettings(session, idUuidPair.getId());
PurgeConfiguration configuration = newDefaultPurgeConfiguration(settings, idUuidPair.getId()); PurgeConfiguration configuration = newDefaultPurgeConfiguration(settings, idUuidPair);


cleanHistoricalData(session, configuration.rootProjectId(), settings); cleanHistoricalData(session, configuration.rootProjectIdUuid().getId(), settings);
doPurge(session, configuration); doPurge(session, configuration);


deleteIndexedIssuesBefore(idUuidPair.getUuid(), configuration.maxLiveDateOfClosedIssues()); deleteIndexedIssuesBefore(idUuidPair.getUuid(), configuration.maxLiveDateOfClosedIssues());
Expand Down Expand Up @@ -105,7 +104,7 @@ private void doPurge(DbSession session, PurgeConfiguration configuration) {
purgeDao.purge(session, configuration, purgeListener); purgeDao.purge(session, configuration, purgeListener);
} catch (Exception e) { } catch (Exception e) {
// purge errors must no fail the report analysis // purge errors must no fail the report analysis
LOG.error("Fail to purge data [id=" + configuration.rootProjectId() + "]", e); LOG.error("Fail to purge data [id=" + configuration.rootProjectIdUuid().getId() + "]", e);
} }
} }
} }
Expand Up @@ -137,7 +137,6 @@ private DefaultIssue setFieldDiffs(DefaultIssue issue, String diffFields, Date a


private DefaultIssue setComponent(DefaultIssue issue, @Nullable ReportComponent component) { private DefaultIssue setComponent(DefaultIssue issue, @Nullable ReportComponent component) {
if (component != null) { if (component != null) {
issue.setComponentId((long) component.id());
issue.setComponentUuid(component.uuid()); issue.setComponentUuid(component.uuid());
} }
return issue; return issue;
Expand Down
Expand Up @@ -70,11 +70,11 @@ public void execute(ComputationContext context) {
boolean saved = false; boolean saved = false;
if (issue.isNew()) { if (issue.isNew()) {
Integer ruleId = ruleCache.get(issue.ruleKey()).getId(); Integer ruleId = ruleCache.get(issue.ruleKey()).getId();
mapper.insert(IssueDto.toDtoForComputationInsert(issue, issue.componentId(), context.getProject().getId(), ruleId, system2.now())); mapper.insert(IssueDto.toDtoForComputationInsert(issue, ruleId, system2.now()));
count++; count++;
saved = true; saved = true;
} else if (issue.isChanged()) { } else if (issue.isChanged()) {
IssueDto dto = IssueDto.toDtoForUpdate(issue, context.getProject().getId(), system2.now()); IssueDto dto = IssueDto.toDtoForUpdate(issue, system2.now());
if (Issue.STATUS_CLOSED.equals(issue.status()) || issue.selectedAt() == null) { if (Issue.STATUS_CLOSED.equals(issue.status()) || issue.selectedAt() == null) {
// Issue is closed by scan or changed by end-user // Issue is closed by scan or changed by end-user
mapper.update(dto); mapper.update(dto);
Expand Down
Expand Up @@ -56,7 +56,7 @@ protected void doInsert(DbSession session, long now, DefaultIssue issue) {


@Override @Override
protected void doUpdate(DbSession session, long now, DefaultIssue issue) { protected void doUpdate(DbSession session, long now, DefaultIssue issue) {
IssueDto dto = IssueDto.toDtoForUpdate(issue, project(session, issue).getId(), now); IssueDto dto = IssueDto.toDtoForUpdate(issue, now);


dbClient.issueDao().update(session, dto); dbClient.issueDao().update(session, dto);
} }
Expand Down
Expand Up @@ -80,8 +80,8 @@ class IssueResultSetIterator extends ResultSetIterator<IssueDoc> {


private static final String SQL_ALL = "select " + StringUtils.join(FIELDS, ",") + " from issues i " + private static final String SQL_ALL = "select " + StringUtils.join(FIELDS, ",") + " from issues i " +
"inner join rules r on r.id=i.rule_id " + "inner join rules r on r.id=i.rule_id " +
"inner join projects p on p.id=i.component_id " + "inner join projects p on p.uuid=i.component_uuid " +
"inner join projects root on root.id=i.root_component_id"; "inner join projects root on root.uuid=i.project_uuid";


private static final String SQL_AFTER_DATE = SQL_ALL + " where i.updated_at>?"; private static final String SQL_AFTER_DATE = SQL_ALL + " where i.updated_at>?";


Expand Down
Expand Up @@ -124,7 +124,7 @@ public void should_insert_new_issues() throws Exception {


storage.save(issue); storage.save(issue);


checkTables("should_insert_new_issues", new String[]{"id", "created_at", "updated_at", "issue_change_creation_date"}, "issues", "issue_changes"); checkTables("should_insert_new_issues", new String[] {"id", "created_at", "updated_at", "issue_change_creation_date"}, "issues", "issue_changes");
} }


@Test @Test
Expand All @@ -143,8 +143,9 @@ public void should_update_issues() throws Exception {
.setNew(false) .setNew(false)
.setChanged(true) .setChanged(true)


// updated fields // updated fields
.setLine(5000) .setLine(5000)
.setProjectUuid("CDEF")
.setDebt(Duration.create(10L)) .setDebt(Duration.create(10L))
.setChecksum("FFFFF") .setChecksum("FFFFF")
.setAuthorLogin("simon") .setAuthorLogin("simon")
Expand All @@ -160,14 +161,14 @@ public void should_update_issues() throws Exception {
.setUpdateDate(date) .setUpdateDate(date)
.setCloseDate(date) .setCloseDate(date)


// unmodifiable fields // unmodifiable fields
.setRuleKey(RuleKey.of("xxx", "unknown")) .setRuleKey(RuleKey.of("xxx", "unknown"))
.setComponentKey("struts:Action") .setComponentKey("struts:Action")
.setProjectKey("struts"); .setProjectKey("struts");


storage.save(issue); storage.save(issue);


checkTables("should_update_issues", new String[]{"id", "created_at", "updated_at", "issue_change_creation_date"}, "issues", "issue_changes"); checkTables("should_update_issues", new String[] {"id", "created_at", "updated_at", "issue_change_creation_date"}, "issues", "issue_changes");
} }


static class FakeRuleFinder implements RuleFinder { static class FakeRuleFinder implements RuleFinder {
Expand Down
Expand Up @@ -62,8 +62,8 @@ public void get_by_key() {
IssueDto issue = sut.selectByKey(session, "ABCDE"); IssueDto issue = sut.selectByKey(session, "ABCDE");
assertThat(issue.getKee()).isEqualTo("ABCDE"); assertThat(issue.getKee()).isEqualTo("ABCDE");
assertThat(issue.getId()).isEqualTo(100L); assertThat(issue.getId()).isEqualTo(100L);
assertThat(issue.getComponentId()).isEqualTo(401); assertThat(issue.getComponentUuid()).isEqualTo("CDEF");
assertThat(issue.getProjectId()).isEqualTo(399); assertThat(issue.getProjectUuid()).isEqualTo("ABCD");
assertThat(issue.getRuleId()).isEqualTo(500); assertThat(issue.getRuleId()).isEqualTo(500);
assertThat(issue.getLanguage()).isEqualTo("java"); assertThat(issue.getLanguage()).isEqualTo("java");
assertThat(issue.getSeverity()).isEqualTo("BLOCKER"); assertThat(issue.getSeverity()).isEqualTo("BLOCKER");
Expand Down Expand Up @@ -107,8 +107,8 @@ public void find_by_action_plan() {
IssueDto issue = issues.get(0); IssueDto issue = issues.get(0);
assertThat(issue.getKee()).isEqualTo("ABCDE"); assertThat(issue.getKee()).isEqualTo("ABCDE");
assertThat(issue.getActionPlanKey()).isEqualTo("AP-1"); assertThat(issue.getActionPlanKey()).isEqualTo("AP-1");
assertThat(issue.getComponentId()).isEqualTo(401); assertThat(issue.getComponentUuid()).isEqualTo("CDEF");
assertThat(issue.getProjectId()).isEqualTo(399); assertThat(issue.getProjectUuid()).isEqualTo("ABCD");
assertThat(issue.getRuleId()).isEqualTo(500); assertThat(issue.getRuleId()).isEqualTo(500);
assertThat(issue.getLanguage()).isEqualTo("java"); assertThat(issue.getLanguage()).isEqualTo("java");
assertThat(issue.getSeverity()).isEqualTo("BLOCKER"); assertThat(issue.getSeverity()).isEqualTo("BLOCKER");
Expand Down
Expand Up @@ -13,8 +13,8 @@
<issues <issues
id="101" id="101"
kee="FGHI" kee="FGHI"
component_id="401" component_uuid="CDEF"
root_component_id="399" project_uuid="ABCD"
rule_id="501" rule_id="501"
severity="CRITICAL" severity="CRITICAL"
manual_severity="[true]" manual_severity="[true]"
Expand Down
@@ -1,10 +1,13 @@
<dataset> <dataset>


<!-- Multi module project --> <!-- Multi module project -->
<projects id="399" kee="struts" root_id="[null]" qualifier="TRK" scope="PRJ" uuid="ABCD" project_uuid="ABCD" module_uuid="[null]" module_uuid_path="." path="[null]"/> <projects id="399" kee="struts" root_id="[null]" qualifier="TRK" scope="PRJ" uuid="ABCD" project_uuid="ABCD"
<projects id="400" kee="struts-core" root_id="399" qualifier="BRC" scope="PRJ" uuid="BCDE" project_uuid="ABCD" module_uuid="ABCD" module_uuid_path=".ABCD.BCDE." module_uuid="[null]" module_uuid_path="." path="[null]"/>
<projects id="400" kee="struts-core" root_id="399" qualifier="BRC" scope="PRJ" uuid="BCDE" project_uuid="ABCD"
module_uuid="ABCD" module_uuid_path=".ABCD.BCDE."
path="struts-core"/> path="struts-core"/>
<projects id="401" kee="Action.java" root_id="400" qualifier="CLA" scope="PRJ" uuid="CDEF" project_uuid="ABCD" module_uuid="BCDE" module_uuid_path=".ABCD.BCDE." <projects id="401" kee="Action.java" root_id="400" qualifier="CLA" scope="PRJ" uuid="CDEF" project_uuid="ABCD"
module_uuid="BCDE" module_uuid_path=".ABCD.BCDE."
path="src/main/java/Action.java"/> path="src/main/java/Action.java"/>


<rules id="500" tags="[null]" system_tags="[null]" plugin_rule_key="AvoidCycle" plugin_name="squid" language="java"/> <rules id="500" tags="[null]" system_tags="[null]" plugin_rule_key="AvoidCycle" plugin_name="squid" language="java"/>
Expand All @@ -13,8 +16,8 @@
<issues <issues
id="100" id="100"
kee="EFGH" kee="EFGH"
component_id="401" component_uuid="CDEF"
root_component_id="399" project_uuid="ABCD"
rule_id="500" rule_id="500"
severity="BLOCKER" severity="BLOCKER"
manual_severity="[false]" manual_severity="[false]"
Expand Down
Expand Up @@ -7,10 +7,8 @@
technical_debt="10" technical_debt="10"
message="[null]" message="[null]"
line="5000" line="5000"
component_id="100"
component_uuid="BCDE" component_uuid="BCDE"
project_uuid="ABCD" project_uuid="ABCD"
root_component_id="10"
rule_id="200" rule_id="200"
created_at="1000000000" created_at="1000000000"
updated_at="1000000000" updated_at="1000000000"
Expand Down
Expand Up @@ -12,10 +12,8 @@
technical_debt="10" technical_debt="10"
message="[null]" message="[null]"
line="5000" line="5000"
component_id="100" component_uuid="BCDE"
component_uuid="[null]" project_uuid="CDEF"
project_uuid="[null]"
root_component_id="10"
rule_id="200" rule_id="200"
created_at="1000000000" created_at="1000000000"
updated_at="2000000000" updated_at="2000000000"
Expand Down
Expand Up @@ -19,10 +19,8 @@
technical_debt="[null]" technical_debt="[null]"
message="[null]" message="[null]"
line="3000" line="3000"
component_id="100" component_uuid="BCDE"
component_uuid="[null]" project_uuid="ABCD"
project_uuid="[null]"
root_component_id="10"
rule_id="200" rule_id="200"
created_at="1000000000" created_at="1000000000"
updated_at="1000000000" updated_at="1000000000"
Expand All @@ -32,5 +30,5 @@
issue_creation_date="2010-01-01" issue_creation_date="2010-01-01"
issue_update_date="2010-02-02" issue_update_date="2010-02-02"
issue_close_date="[null]" issue_close_date="[null]"
/> />
</dataset> </dataset>
Expand Up @@ -3,8 +3,8 @@
<issues <issues
id="100" id="100"
kee="ABCDE" kee="ABCDE"
component_id="401" component_uuid="CDEF"
root_component_id="399" project_uuid="ABCD"
rule_id="500" rule_id="500"
severity="BLOCKER" severity="BLOCKER"
manual_severity="[false]" manual_severity="[false]"
Expand Down
Expand Up @@ -3,8 +3,8 @@
<issues <issues
id="100" id="100"
kee="ABCDE" kee="ABCDE"
component_id="401" component_uuid="CDEF"
root_component_id="399" project_uuid="ABCD"
rule_id="500" rule_id="500"
severity="BLOCKER" severity="BLOCKER"
manual_severity="[false]" manual_severity="[false]"
Expand Down
Expand Up @@ -2,10 +2,8 @@
<issues <issues
id="100" id="100"
kee="ABCDE" kee="ABCDE"
component_id="123"
component_uuid="component-uuid" component_uuid="component-uuid"
project_uuid="project-uuid" project_uuid="project-uuid"
root_component_id="100"
rule_id="200" rule_id="200"
severity="BLOCKER" severity="BLOCKER"
manual_severity="[false]" manual_severity="[false]"
Expand Down
Expand Up @@ -4,8 +4,8 @@
<issues <issues
id="100" id="100"
kee="100" kee="100"
component_id="401" component_uuid="CDEF"
root_component_id="399" project_uuid="ABCD"
rule_id="500" rule_id="500"
severity="BLOCKER" severity="BLOCKER"
manual_severity="[false]" manual_severity="[false]"
Expand All @@ -30,8 +30,8 @@
<issues <issues
id="101" id="101"
kee="101" kee="101"
component_id="402" component_uuid="DEFG"
root_component_id="399" project_uuid="ABCD"
rule_id="501" rule_id="501"
severity="MAJOR" severity="MAJOR"
manual_severity="[false]" manual_severity="[false]"
Expand All @@ -56,8 +56,8 @@
<issues <issues
id="102" id="102"
kee="102" kee="102"
component_id="402" component_uuid="DEFG"
root_component_id="399" project_uuid="ABCD"
rule_id="501" rule_id="501"
severity="MAJOR" severity="MAJOR"
manual_severity="[false]" manual_severity="[false]"
Expand All @@ -82,8 +82,8 @@
<issues <issues
id="103" id="103"
kee="103" kee="103"
component_id="400" component_uuid="BCDE"
root_component_id="399" project_uuid="ABCD"
rule_id="501" rule_id="501"
severity="MAJOR" severity="MAJOR"
manual_severity="[false]" manual_severity="[false]"
Expand All @@ -108,8 +108,8 @@
<issues <issues
id="104" id="104"
kee="104" kee="104"
component_id="399" component_uuid="ABCD"
root_component_id="399" project_uuid="ABCD"
rule_id="501" rule_id="501"
severity="MAJOR" severity="MAJOR"
manual_severity="[false]" manual_severity="[false]"
Expand All @@ -134,8 +134,8 @@
<issues <issues
id="1000" id="1000"
kee="1000" kee="1000"
component_id="1001" component_uuid="EDCB"
root_component_id="1000" project_uuid="DBCA"
rule_id="500" rule_id="500"
severity="BLOCKER" severity="BLOCKER"
manual_severity="[true]" manual_severity="[true]"
Expand Down
Expand Up @@ -4,8 +4,8 @@
<issues <issues
id="100" id="100"
kee="100" kee="100"
component_id="401" component_uuid="CDEF"
root_component_id="399" project_uuid="ABCD"
rule_id="500" rule_id="500"
severity="BLOCKER" severity="BLOCKER"
manual_severity="[false]" manual_severity="[false]"
Expand All @@ -30,8 +30,8 @@
<issues <issues
id="101" id="101"
kee="101" kee="101"
component_id="402" component_uuid="DEFG"
root_component_id="399" project_uuid="ABCD"
rule_id="501" rule_id="501"
severity="MAJOR" severity="MAJOR"
manual_severity="[false]" manual_severity="[false]"
Expand All @@ -56,8 +56,8 @@
<issues <issues
id="102" id="102"
kee="102" kee="102"
component_id="402" component_uuid="DEFG"
root_component_id="399" project_uuid="ABCD"
rule_id="501" rule_id="501"
severity="MAJOR" severity="MAJOR"
manual_severity="[false]" manual_severity="[false]"
Expand All @@ -82,8 +82,8 @@
<issues <issues
id="103" id="103"
kee="103" kee="103"
component_id="400" component_uuid="BCDE"
root_component_id="399" project_uuid="ABCD"
rule_id="501" rule_id="501"
severity="MAJOR" severity="MAJOR"
manual_severity="[false]" manual_severity="[false]"
Expand All @@ -108,8 +108,8 @@
<issues <issues
id="104" id="104"
kee="104" kee="104"
component_id="399" component_uuid="ABCD"
root_component_id="399" project_uuid="ABCD"
rule_id="501" rule_id="501"
severity="MAJOR" severity="MAJOR"
manual_severity="[false]" manual_severity="[false]"
Expand All @@ -134,8 +134,8 @@
<issues <issues
id="1000" id="1000"
kee="1000" kee="1000"
component_id="1001" component_uuid="EDCB"
root_component_id="1000" project_uuid="DBCA"
rule_id="500" rule_id="500"
severity="BLOCKER" severity="BLOCKER"
manual_severity="[true]" manual_severity="[true]"
Expand Down

0 comments on commit 341bc8e

Please sign in to comment.