remove dangling stacktraces

This commit is contained in:
f43nd1r 2019-12-07 00:58:20 +01:00
parent 0a83704f19
commit 61ac16c810

View file

@ -15,12 +15,7 @@
*/ */
package com.faendir.acra.service; package com.faendir.acra.service;
import com.faendir.acra.model.App; import com.faendir.acra.model.*;
import com.faendir.acra.model.Bug;
import com.faendir.acra.model.QBug;
import com.faendir.acra.model.QStacktrace;
import com.faendir.acra.model.Stacktrace;
import com.faendir.acra.model.StacktraceMatch;
import com.mysema.commons.lang.CloseableIterator; import com.mysema.commons.lang.CloseableIterator;
import com.querydsl.core.Tuple; import com.querydsl.core.Tuple;
import com.querydsl.jpa.JPAExpressions; import com.querydsl.jpa.JPAExpressions;
@ -46,6 +41,7 @@ import java.util.List;
import static com.faendir.acra.model.QApp.app; import static com.faendir.acra.model.QApp.app;
import static com.faendir.acra.model.QBug.bug; import static com.faendir.acra.model.QBug.bug;
import static com.faendir.acra.model.QReport.report;
import static com.faendir.acra.model.QStacktrace.stacktrace1; import static com.faendir.acra.model.QStacktrace.stacktrace1;
import static com.faendir.acra.model.QStacktraceMatch.stacktraceMatch; import static com.faendir.acra.model.QStacktraceMatch.stacktraceMatch;
@ -163,9 +159,15 @@ public class BugMerger {
@EventListener @EventListener
@Transactional @Transactional
public void onReportsDeleted(ReportsDeleteEvent event) { public void onReportsDeleted(ReportsDeleteEvent event) {
deleteOrphanStacktraces();
deleteOrphanBugs(); deleteOrphanBugs();
} }
@Transactional
public void deleteOrphanStacktraces() {
new JPADeleteClause(entityManager, stacktrace1).where(stacktrace1.notIn(JPAExpressions.select(report.stacktrace).from(report).distinct())).execute();
}
@Transactional @Transactional
public void deleteOrphanBugs() { public void deleteOrphanBugs() {
new JPADeleteClause(entityManager, bug).where(bug.notIn(JPAExpressions.select(stacktrace1.bug).from(stacktrace1).distinct())).execute(); new JPADeleteClause(entityManager, bug).where(bug.notIn(JPAExpressions.select(stacktrace1.bug).from(stacktrace1).distinct())).execute();