Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optimize: 优化第三方同步在多线程下同步出现重复条目的情况 #711

Merged
merged 1 commit into from
Oct 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.MD
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

更新日志文档,版本顺序从新到旧,最新版本在最前(上)面。

# 0.17.7

- 优化第三方同步在多线程下同步出现重复条目的情况

# 0.17.6

- 优化查询条目剧集数的逻辑
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version=0.17.6
version=0.17.7
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import jakarta.annotation.Nullable;
import jakarta.validation.constraints.NotNull;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArraySet;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
Expand Down Expand Up @@ -36,6 +38,7 @@ public class SubjectSyncPlatformServiceImpl implements SubjectSyncPlatformServic
private final SubjectService subjectService;
private ApplicationContext applicationContext;
private final SubjectSyncRepository subjectSyncRepository;
private final Set<String> pullingPlatformIdSet = new CopyOnWriteArraySet<>();

/**
* Construct.
Expand Down Expand Up @@ -219,6 +222,10 @@ public Mono<SubjectSync> findBySubjectIdAndPlatformAndPlatformId(Long subjectId,
private Mono<Subject> syncBySubjectSynchronizer(@Nullable Long subjectId,
SubjectSyncPlatform platform,
String platformId) {
if (pullingPlatformIdSet.contains(platformId)) {
return Mono.empty();
}
pullingPlatformIdSet.add(platformId);
return Flux.fromStream(extensionComponentsFinder.getExtensions(SubjectSynchronizer.class)
.stream())
.filter(subjectSynchronizer -> platform.equals(subjectSynchronizer.getSyncPlatform()))
Expand All @@ -228,6 +235,7 @@ private Mono<Subject> syncBySubjectSynchronizer(@Nullable Long subjectId,
"No found available subject platform synchronizer for platform-id: "
+ platform.name() + "-" + platformId)))
.map(subjectSynchronizes -> subjectSynchronizes.get(0))
.subscribeOn(Schedulers.boundedElastic())
.flatMap(subjectSynchronizer -> subjectSynchronizer.pull(platformId))
.onErrorResume(Exception.class, e -> {
String msg =
Expand All @@ -244,7 +252,7 @@ private Mono<Subject> syncBySubjectSynchronizer(@Nullable Long subjectId,
.map(sub -> sub.setId(null)).flatMap(subjectService::create))
: subjectService.update(subject)
.then(Mono.defer(() -> subjectService.findById(subjectId))))
.subscribeOn(Schedulers.boundedElastic());
.doFinally(signalType -> pullingPlatformIdSet.remove(platformId));
}


Expand Down
Loading