Skip to content

Commit

Permalink
fix: apply natural ordering to policy and attachment listings (#160)
Browse files Browse the repository at this point in the history
```release-note
None
```
传递unsorted以支持Halo 2.17版本
  • Loading branch information
longjuan authored Jul 2, 2024
1 parent bdd62cb commit cb968de
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/main/java/run/halo/s3os/S3LinkServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static run.halo.s3os.S3OsAttachmentHandler.OBJECT_KEY;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand All @@ -14,6 +15,7 @@
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.data.domain.Sort;
import org.springframework.http.HttpStatus;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.ReactiveSecurityContextHolder;
Expand Down Expand Up @@ -53,7 +55,7 @@ public class S3LinkServiceImpl implements S3LinkService {
@Override
public Flux<Policy> listS3Policies() {
return client.list(Policy.class, (policy) -> "s3os".equals(
policy.getSpec().getTemplateName()), null);
policy.getSpec().getTemplateName()), Comparator.naturalOrder());
}

@Override
Expand Down Expand Up @@ -90,7 +92,7 @@ public Mono<S3ListResult> listObjects(String policyName, String continuationToke
ListOptions listOptions = new ListOptions();
listOptions.setFieldSelector(
FieldSelector.of(QueryFactory.equal("spec.policyName", policyName)));
return client.listAll(Attachment.class, listOptions, null)
return client.listAll(Attachment.class, listOptions, Sort.unsorted())
.doOnNext(attachment -> {
S3ListResult.ObjectVo objectVo =
objectVos.get(attachment.getMetadata().getAnnotations()
Expand Down Expand Up @@ -132,7 +134,7 @@ private Mono<Set<String>> getExistingAttachments(Set<String> objectKeys,
ListOptions listOptions = new ListOptions();
listOptions.setFieldSelector(
FieldSelector.of(QueryFactory.equal("spec.policyName", policyName)));
return client.listAll(Attachment.class, listOptions, null)
return client.listAll(Attachment.class, listOptions, Sort.unsorted())
.filter(attachment -> StringUtils.isNotBlank(
MetadataUtil.nullSafeAnnotations(attachment).get(S3OsAttachmentHandler.OBJECT_KEY))
&& objectKeys.contains(
Expand Down

0 comments on commit cb968de

Please sign in to comment.