Browse Source

DEC-17013 fix: 【S3插件】备份模板很慢,有生成多余文件,后台很多警告

persist/10.0
Feng 4 years ago
parent
commit
893bbae5b4
  1. 29
      src/main/java/com/fanruan/fs/s3/repository/core/S3ResourceRepository.java

29
src/main/java/com/fanruan/fs/s3/repository/core/S3ResourceRepository.java

@ -19,7 +19,6 @@ import com.fanruan.api.util.StringKit;
import com.fr.io.repository.FineFileEntry; import com.fr.io.repository.FineFileEntry;
import com.fr.io.repository.base.BaseResourceRepository; import com.fr.io.repository.base.BaseResourceRepository;
import com.fr.stable.Filter; import com.fr.stable.Filter;
import com.fr.stable.StringUtils;
import com.fr.workspace.resource.ResourceIOException; import com.fr.workspace.resource.ResourceIOException;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
@ -58,11 +57,9 @@ public class S3ResourceRepository extends BaseResourceRepository {
@Override @Override
public FineFileEntry getEntry(String path) { public FineFileEntry getEntry(String path) {
GetObjectRequest request = new GetObjectRequest(bucket, path);
try { try {
try (S3Object s3Object = s3.getObject(request)) { ObjectMetadata metadata = s3.getObjectMetadata(bucket, path);
return s3Object2FileEntry(s3Object, path); return s3Object2FileEntry(metadata, path);
}
} catch (Exception e) { } catch (Exception e) {
LogKit.info("{} not exist!", path); LogKit.info("{} not exist!", path);
} }
@ -225,7 +222,7 @@ public class S3ResourceRepository extends BaseResourceRepository {
for (S3ObjectSummary objectSummary : objectListing.getObjectSummaries()) { for (S3ObjectSummary objectSummary : objectListing.getObjectSummaries()) {
String key = objectSummary.getKey(); String key = objectSummary.getKey();
if (StringUtils.equals(key, dir)) { if (StringKit.equals(key, dir)) {
continue; continue;
} }
String[] arr = key.split(DELIMITER); String[] arr = key.split(DELIMITER);
@ -291,14 +288,8 @@ public class S3ResourceRepository extends BaseResourceRepository {
@Override @Override
public long length(String path) { public long length(String path) {
try { try {
S3Object s3Object = s3.getObject(bucket, path); ObjectMetadata metadata = s3.getObjectMetadata(bucket, path);
if (s3Object != null) { return metadata.getContentLength();
try {
return s3Object.getObjectMetadata().getContentLength();
} finally {
s3Object.close();
}
}
} catch (Exception e) { } catch (Exception e) {
LogKit.info("{} not exist!", path); LogKit.info("{} not exist!", path);
} }
@ -342,17 +333,17 @@ public class S3ResourceRepository extends BaseResourceRepository {
private FineFileEntry s3Object2FileEntry(S3ObjectSummary s3Object, String path) { private FineFileEntry s3Object2FileEntry(S3ObjectSummary s3Object, String path) {
FineFileEntry entry = new FineFileEntry(path); FineFileEntry entry = new FineFileEntry(path);
entry.setDirectory(s3Object.getKey().endsWith("/")); entry.setDirectory(s3Object.getKey().endsWith(DELIMITER));
entry.setSize(s3Object.getSize()); entry.setSize(s3Object.getSize());
entry.setTimestamp(s3Object.getLastModified().getTime()); entry.setTimestamp(s3Object.getLastModified().getTime());
return entry; return entry;
} }
private FineFileEntry s3Object2FileEntry(S3Object s3Object, String path) { private FineFileEntry s3Object2FileEntry(ObjectMetadata metadata, String path) {
FineFileEntry entry = new FineFileEntry(path); FineFileEntry entry = new FineFileEntry(path);
entry.setDirectory(s3Object.getKey().endsWith("/")); entry.setDirectory(path.endsWith(DELIMITER));
entry.setSize(s3Object.getObjectMetadata().getContentLength()); entry.setSize(metadata.getContentLength());
entry.setTimestamp(s3Object.getObjectMetadata().getLastModified().getTime()); entry.setTimestamp(metadata.getLastModified().getTime());
return entry; return entry;
} }

Loading…
Cancel
Save