Skip to content

Commit

Permalink
Revert transactional changes to FileHandler
Browse files Browse the repository at this point in the history
Closes 957
  • Loading branch information
theotherp committed Jun 10, 2024
1 parent 104f451 commit 2fa3945
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
15 changes: 6 additions & 9 deletions core/src/main/java/org/nzbhydra/downloading/FileHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.google.common.base.Stopwatch;
import com.google.common.collect.Sets;
import lombok.Getter;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
Expand Down Expand Up @@ -83,12 +82,10 @@ public class FileHandler {
@Autowired
private IndexerSpecificDownloadExceptions indexerSpecificDownloadExceptions;

@Getter
private final Set<File> temporaryZipFiles = new HashSet<>();
@Autowired
private TempFileProvider tempFileProvider;

@Transactional
public DownloadResult getFileByGuid(long guid, SearchSource accessSource) throws InvalidSearchResultIdException {
final SearchResultEntity searchResult = getResultFromGuid(guid, accessSource);
final IndexerConfig indexerConfig = configProvider.getIndexerByName(searchResult.getIndexer().getName());
Expand Down Expand Up @@ -123,8 +120,7 @@ public DownloadResult getFileByResult(FileDownloadAccessType fileDownloadAccessT
return getFileByResult(fileDownloadAccessType, accessSource, result, new HashSet<>());
}

@Transactional
DownloadResult getFileByResult(FileDownloadAccessType fileDownloadAccessType, SearchSource accessSource, SearchResultEntity result, Set<SearchResultEntity> alreadyTriedDownloading) {
private DownloadResult getFileByResult(FileDownloadAccessType fileDownloadAccessType, SearchSource accessSource, SearchResultEntity result, Set<SearchResultEntity> alreadyTriedDownloading) {
logger.info("{} download request for \"{}\" from indexer {}", fileDownloadAccessType, result.getTitle(), result.getIndexer().getName());
if (fileDownloadAccessType == FileDownloadAccessType.REDIRECT) {
return handleRedirect(accessSource, result, null);
Expand Down Expand Up @@ -221,7 +217,6 @@ private void publishEvents(SearchResultEntity result, FileDownloadEntity downloa
}


@Transactional
public FileZipResponse getFilesAsZip(List<Long> guids) throws Exception {
Path tempDirectory;
try {
Expand All @@ -244,8 +239,7 @@ public FileZipResponse getFilesAsZip(List<Long> guids) throws Exception {
return new FileZipResponse(true, zip.getAbsolutePath(), message, nzbsDownload.successfulIds, nzbsDownload.failedIds);
}

@Transactional
NzbsDownload getNzbsAsFiles(Collection<Long> guids, Path targetDirectory) {
private NzbsDownload getNzbsAsFiles(Collection<Long> guids, Path targetDirectory) {
final NzbsDownload nzbsDownload;

final List<File> files = new ArrayList<>();
Expand Down Expand Up @@ -417,7 +411,6 @@ private byte[] handleRedirect(SearchResultEntity result, Response response) thro
throw new DownloadException(result.getLink(), 500, "Unable to handle redirect from URL " + result.getLink() + " because no redirection location is set");
}

@Transactional
public GenericResponse saveNzbToBlackhole(Long searchResultId) {
if (configProvider.getBaseConfig().getDownloading().getSaveNzbsTo().isEmpty()) {
//Shouldn't happen
Expand All @@ -431,6 +424,10 @@ public GenericResponse saveNzbToBlackhole(Long searchResultId) {
return GenericResponse.ok();
}

public Set<File> getTemporaryZipFiles() {
return temporaryZipFiles;
}

private static class NzbsDownload {
private final List<File> files;
private final List<Long> successfulIds;
Expand Down
3 changes: 2 additions & 1 deletion core/src/main/java/org/nzbhydra/indexers/Binsearch.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import dev.failsafe.RetryPolicy;
import dev.failsafe.function.CheckedSupplier;
import joptsimple.internal.Strings;
import org.apache.commons.lang3.StringUtils;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
Expand Down Expand Up @@ -158,7 +159,7 @@ private SearchResultItem parseRow(Element row) {
item.setTitle(title);

item.setIndexerGuid(getElementOrNone(row, "input[type=checkbox]").attr("name"));
item.setLink("https://binsearch.info/nzb?mode=files&%s=on&name=%s".formatted(item.getIndexerGuid(), filename + ".nzb"));
item.setLink("https://binsearch.info/nzb?mode=files&%s=on&name=%s".formatted(item.getIndexerGuid(), StringUtils.removeEnd(filename, ".nzb") + ".nzb"));
Element infoElement = getElementOrNone(row, "td:nth-child(3) > div:nth-child(1) > div");
if (infoElement == null) {
debug("Ignored entry because it has no info");
Expand Down
6 changes: 6 additions & 0 deletions core/src/main/resources/changelog.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
#@formatter:off
- version: "v7.2.3"
date: "2024-06-10"
changes:
- type: "fix"
text: "Roll back changes that causes errors when downloading NZBs (which kinda sounds like I did those on purpose, but I didn't, really!) See #957"
final: true
- version: "v7.2.2"
date: "2024-06-08"
changes:
Expand Down

0 comments on commit 2fa3945

Please sign in to comment.