forked from Qortal/qortal
If a single file resource is being published and a complete file patch has been chosen, make sure to use PUT instead of PATCH as there's nothing to be gained by adding another layer.
This would have been caught by the max differences check anyway, but it's a good check to have in place in case we recalibrate or remove the differences check in the future.
This commit is contained in:
parent
8e36c456e1
commit
4866e5050a
@ -2,6 +2,7 @@ package org.qortal.arbitrary;
|
|||||||
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
import org.qortal.arbitrary.metadata.ArbitraryDataMetadataPatch;
|
||||||
import org.qortal.repository.DataException;
|
import org.qortal.repository.DataException;
|
||||||
import org.qortal.settings.Settings;
|
import org.qortal.settings.Settings;
|
||||||
import org.qortal.utils.FilesystemUtils;
|
import org.qortal.utils.FilesystemUtils;
|
||||||
@ -23,6 +24,7 @@ public class ArbitraryDataCreatePatch {
|
|||||||
private Path finalPath;
|
private Path finalPath;
|
||||||
private int totalFileCount;
|
private int totalFileCount;
|
||||||
private int fileDifferencesCount;
|
private int fileDifferencesCount;
|
||||||
|
private ArbitraryDataMetadataPatch metadata;
|
||||||
|
|
||||||
private Path workingPath;
|
private Path workingPath;
|
||||||
private String identifier;
|
private String identifier;
|
||||||
@ -121,7 +123,7 @@ public class ArbitraryDataCreatePatch {
|
|||||||
diff.compute();
|
diff.compute();
|
||||||
|
|
||||||
this.totalFileCount = diff.getTotalFileCount();
|
this.totalFileCount = diff.getTotalFileCount();
|
||||||
this.fileDifferencesCount = diff.getFileDifferencesCount();
|
this.metadata = diff.getMetadata();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Path getFinalPath() {
|
public Path getFinalPath() {
|
||||||
@ -132,8 +134,8 @@ public class ArbitraryDataCreatePatch {
|
|||||||
return this.totalFileCount;
|
return this.totalFileCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getFileDifferencesCount() {
|
public ArbitraryDataMetadataPatch getMetadata() {
|
||||||
return this.fileDifferencesCount;
|
return this.metadata;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -75,6 +75,7 @@ public class ArbitraryDataDiff {
|
|||||||
private final List<Path> removedPaths;
|
private final List<Path> removedPaths;
|
||||||
|
|
||||||
private int totalFileCount;
|
private int totalFileCount;
|
||||||
|
private ArbitraryDataMetadataPatch metadata;
|
||||||
|
|
||||||
public ArbitraryDataDiff(Path pathBefore, Path pathAfter, byte[] previousSignature) throws DataException {
|
public ArbitraryDataDiff(Path pathBefore, Path pathAfter, byte[] previousSignature) throws DataException {
|
||||||
this.pathBefore = pathBefore;
|
this.pathBefore = pathBefore;
|
||||||
@ -258,6 +259,9 @@ public class ArbitraryDataDiff {
|
|||||||
diff.removedPaths.add(filePathBefore);
|
diff.removedPaths.add(filePathBefore);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Keep a tally of the total number of files to help with decision making
|
||||||
|
diff.totalFileCount++;
|
||||||
|
|
||||||
return FileVisitResult.CONTINUE;
|
return FileVisitResult.CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -300,6 +304,7 @@ public class ArbitraryDataDiff {
|
|||||||
metadata.setPreviousHash(this.previousHash);
|
metadata.setPreviousHash(this.previousHash);
|
||||||
metadata.setCurrentHash(this.currentHash);
|
metadata.setCurrentHash(this.currentHash);
|
||||||
metadata.write();
|
metadata.write();
|
||||||
|
this.metadata = metadata;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -360,8 +365,8 @@ public class ArbitraryDataDiff {
|
|||||||
return this.totalFileCount;
|
return this.totalFileCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getFileDifferencesCount() {
|
public ArbitraryDataMetadataPatch getMetadata() {
|
||||||
return this.addedPaths.size() + this.modifiedPaths.size() + this.removedPaths.size();
|
return this.metadata;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -4,6 +4,8 @@ import org.apache.logging.log4j.LogManager;
|
|||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.qortal.arbitrary.exception.MissingDataException;
|
import org.qortal.arbitrary.exception.MissingDataException;
|
||||||
import org.qortal.arbitrary.ArbitraryDataFile.ResourceIdType;
|
import org.qortal.arbitrary.ArbitraryDataFile.ResourceIdType;
|
||||||
|
import org.qortal.arbitrary.ArbitraryDataDiff.*;
|
||||||
|
import org.qortal.arbitrary.metadata.ArbitraryDataMetadataPatch;
|
||||||
import org.qortal.arbitrary.misc.Service;
|
import org.qortal.arbitrary.misc.Service;
|
||||||
import org.qortal.block.BlockChain;
|
import org.qortal.block.BlockChain;
|
||||||
import org.qortal.crypto.Crypto;
|
import org.qortal.crypto.Crypto;
|
||||||
@ -113,14 +115,30 @@ public class ArbitraryDataTransactionBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check number of modified files
|
// Check number of modified files
|
||||||
|
ArbitraryDataMetadataPatch metadata = patch.getMetadata();
|
||||||
int totalFileCount = patch.getTotalFileCount();
|
int totalFileCount = patch.getTotalFileCount();
|
||||||
int differencesCount = patch.getFileDifferencesCount();
|
int differencesCount = metadata.getFileDifferencesCount();
|
||||||
difference = (double) differencesCount / (double) totalFileCount;
|
difference = (double) differencesCount / (double) totalFileCount;
|
||||||
if (difference > MAX_FILE_DIFF) {
|
if (difference > MAX_FILE_DIFF) {
|
||||||
LOGGER.info("Reached maximum file differences ({} / {}) - using PUT", difference, MAX_FILE_DIFF);
|
LOGGER.info("Reached maximum file differences ({} / {}) - using PUT", difference, MAX_FILE_DIFF);
|
||||||
return Method.PUT;
|
return Method.PUT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check the patch types
|
||||||
|
// Limit this check to single file resources only for now
|
||||||
|
boolean atLeastOnePatch = false;
|
||||||
|
if (totalFileCount == 1) {
|
||||||
|
for (ModifiedPath path : metadata.getModifiedPaths()) {
|
||||||
|
if (path.getDiffType() != DiffType.COMPLETE_FILE) {
|
||||||
|
atLeastOnePatch = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!atLeastOnePatch) {
|
||||||
|
LOGGER.info("Patch consists of complete files only - using PUT");
|
||||||
|
return Method.PUT;
|
||||||
|
}
|
||||||
|
|
||||||
// State is appropriate for a PATCH transaction
|
// State is appropriate for a PATCH transaction
|
||||||
return Method.PATCH;
|
return Method.PATCH;
|
||||||
}
|
}
|
||||||
|
@ -174,4 +174,9 @@ public class ArbitraryDataMetadataPatch extends ArbitraryDataMetadata {
|
|||||||
return this.currentHash;
|
return this.currentHash;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public int getFileDifferencesCount() {
|
||||||
|
return this.addedPaths.size() + this.modifiedPaths.size() + this.removedPaths.size();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user