-
-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- add helper tool to optimize history db. Especially older converted …
…histories may contain duplicate data which might sloe down processing.
- Loading branch information
1 parent
fecd883
commit 403e055
Showing
4 changed files
with
105 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
src/main/java/mediathek/gui/actions/OptimizeHistoryDbAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package mediathek.gui.actions; | ||
|
||
import mediathek.config.Konstanten; | ||
import mediathek.controller.history.SeenHistoryController; | ||
import mediathek.mainwindow.MediathekGui; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
|
||
import javax.swing.*; | ||
import java.awt.event.ActionEvent; | ||
import java.sql.SQLException; | ||
|
||
public class OptimizeHistoryDbAction extends AbstractAction { | ||
private final MediathekGui mediathekGui; | ||
private static final Logger logger = LogManager.getLogger(); | ||
|
||
public OptimizeHistoryDbAction(MediathekGui mediathekGui) { | ||
this.mediathekGui = mediathekGui; | ||
putValue(NAME, "History-Datenbank optimieren..."); | ||
} | ||
|
||
@Override | ||
public void actionPerformed(ActionEvent e) { | ||
try (SeenHistoryController controller = new SeenHistoryController()) { | ||
var dupes = controller.checkDuplicates(); | ||
var numDuplicates = dupes.total() - dupes.distinct(); | ||
logger.trace("{} duplicates found in history", numDuplicates); | ||
if (numDuplicates == 0) { | ||
//no duplicates | ||
var msg = "Es sind keine Duplikate vorhanden.\nEine Optimierung ist nicht notwendig."; | ||
JOptionPane.showMessageDialog(mediathekGui, msg, Konstanten.PROGRAMMNAME, JOptionPane.INFORMATION_MESSAGE); | ||
} | ||
else { | ||
var msg = String.format("Es wurden %d Duplikate gefunden.\nMöchten Sie diese bereinigen?", numDuplicates); | ||
var answer = JOptionPane.showOptionDialog(mediathekGui, msg, Konstanten.PROGRAMMNAME, | ||
JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null); | ||
if (answer == JOptionPane.YES_OPTION) { | ||
controller.removeDuplicates(); | ||
dupes = controller.checkDuplicates(); | ||
numDuplicates = dupes.total() - dupes.distinct(); | ||
logger.trace("{} duplicates found in history after cleanup", numDuplicates); | ||
msg = String.format("Datenbank wurde bereinigt.\n%d Duplikate blieben übrig.", numDuplicates); | ||
JOptionPane.showMessageDialog(mediathekGui, msg, Konstanten.PROGRAMMNAME, JOptionPane.INFORMATION_MESSAGE); | ||
} | ||
} | ||
} catch (SQLException ex) { | ||
JOptionPane.showMessageDialog(mediathekGui, ex.getMessage(), Konstanten.PROGRAMMNAME, JOptionPane.ERROR_MESSAGE); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters