WIP: Some performance improvements (maybe)

This commit is contained in:
grimsi
2022-07-24 20:45:09 +02:00
parent e1a285a77d
commit aa8fd0d613
4 changed files with 14 additions and 29 deletions
-5
View File
@@ -76,11 +76,6 @@
<artifactId>commons-io</artifactId>
<version>${commons-io.version}</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-compress</artifactId>
<version>${commons-compress.version}</version>
</dependency>
<!-- Protobuf dependencies -->
<dependency>
@@ -45,7 +45,9 @@ import java.util.concurrent.ExecutionException;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import java.util.zip.Deflater;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
@Slf4j
@Service
@@ -276,37 +278,24 @@ public class FilesystemService {
}
private void downloadFilesAsZip(Path path, OutputStream outputStream) {
final ParallelScatterZipCreator scatterZipCreator = new ParallelScatterZipCreator();
ZipArchiveOutputStream zipArchiveOutputStream;
zipArchiveOutputStream = new ZipArchiveOutputStream(outputStream);
zipArchiveOutputStream.setUseZip64(Zip64Mode.AsNeeded);
ZipOutputStream zos = new ZipOutputStream(outputStream){{
def.setLevel(Deflater.NO_COMPRESSION);
}};
try {
Files.walkFileTree(path, new SimpleFileVisitor<>() {
@SneakyThrows
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
InputStreamSupplier streamSupplier = () -> {
InputStream is = null;
try {
is = Files.newInputStream(file);
} catch (IOException e) {
e.printStackTrace();
}
return is;
};
ZipArchiveEntry zipArchiveEntry = new ZipArchiveEntry(path.relativize(file).toString());
zipArchiveEntry.setMethod(ZipEntry.STORED);
scatterZipCreator.addArchiveEntry(zipArchiveEntry, streamSupplier);
zos.putNextEntry(new ZipEntry(path.relativize(file).toString()));
Files.copy(file, zos);
zos.closeEntry();
return FileVisitResult.CONTINUE;
}
});
scatterZipCreator.writeTo(zipArchiveOutputStream);
zipArchiveOutputStream.close();
} catch (IOException | InterruptedException | ExecutionException e) {
zos.close();
} catch (IOException e) {
log.error("Error while zipping files:", e);
}
}
@@ -1,7 +1,6 @@
gameyfin:
#root: C:\Projects\privat\gameyfin-library
#root: \\NAS-Simon\Öffentlich\Spiele
root: C:\gameyfin-library
root: \\NAS-Simon\Öffentlich\Spiele
cache: ${gameyfin.root}\.gameyfin\cache
#db: ${gameyfin.root}\.gameyfin\db
db: ./data
@@ -3,6 +3,8 @@ server:
error.include-stacktrace: never
spring:
mvc:
async.request-timeout: -1
jackson.default-property-inclusion: non_null
datasource.db-name: gameyfin_db
datasource.url: jdbc:h2:file:${gameyfin.db}/${spring.datasource.db-name};AUTO_SERVER=TRUE