Skip to content
This repository has been archived by the owner on Apr 5, 2024. It is now read-only.

Commit

Permalink
Merge pull request #104 from eivindveg/hotfix/2.0.2
Browse files Browse the repository at this point in the history
Release Hotfix/2.0.2
  • Loading branch information
zhedar committed Feb 15, 2016
2 parents e8ac6fa + f37fd3d commit 7787367
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 27 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>ninja.eivind</groupId>
<artifactId>hots-replay-uploader</artifactId>
<version>2.0.1</version>
<version>2.0.2</version>

<prerequisites>
<maven>3.0</maven>
Expand All @@ -15,7 +15,7 @@
<developers>
<developer>
<name>Eivind Vegsundvåg</name>
<email>eivindveg hotmail com</email>
<email>mail at eivind dot ninja</email>
<timezone>CET</timezone>
<roles>
<role>Developer</role>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,10 @@
import javax.inject.Inject;
import javax.inject.Singleton;
import java.io.Closeable;
import java.io.File;
import java.io.IOException;
import java.sql.SQLException;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.stream.Collectors;

/**
* Implementation of a {@link FileRepository}, which is based on a database backend.<br>
Expand Down Expand Up @@ -79,40 +77,36 @@ public void updateReplay(final ReplayFile file) {

@Override
public List<ReplayFile> getAll() {
return accountDirectoryWatcher.getAllFiles()
//update the DB with any file changes first
accountDirectoryWatcher.getAllFiles()
.map(ReplayFile::fromDirectory)
.map(this::refreshAll)
// TODO Replace with SELECT IN statement. Needs readding of missing files. Improves performance
.flatMap(List::stream)
.map(replayFile -> {
File file = replayFile.getFile();
if (file.exists()) {
return replayFile;
} else {
deleteReplay(replayFile);
return null;
}
})
.filter(file -> file != null) //dont list already deleted files
.collect(Collectors.toList());
.forEach(this::checkForDatabaseIntegrity);

//get a fully refreshed copy containing all changes from the db
try {
return dao.queryForAll();
} catch (SQLException e) {
throw new RuntimeException(e);
}
}

private List<ReplayFile> refreshAll(List<ReplayFile> replayFiles) {
private void checkForDatabaseIntegrity(List<ReplayFile> replayFiles) {
try {
final List<ReplayFile> fromDb = dao.queryForAll();

//start a batch task to speed up initial startups
dao.callBatchTasks(new Callable<Void>() {
public Void call() throws Exception {
//create new db entities for new files
replayFiles.stream()
.filter(file -> !fromDb.contains(file))
.forEach(file -> createReplay(file));
for(ReplayFile replayFile : replayFiles) {
if(!fromDb.contains(replayFile))
createReplay(replayFile);
else if(!replayFile.getFile().exists())
deleteReplay(replayFile);
}

return null;
}
});

//get all entities again, but fresh from the db
return dao.queryForAll();
} catch (Exception e) {
throw new RuntimeException(e);
}
Expand Down

0 comments on commit 7787367

Please sign in to comment.