Fix: artist disappearing from feed on type toggle - fetch all from MBZ first, then swap atomically
This commit is contained in:
@@ -8,7 +8,10 @@ import java.time.Instant;
|
||||
import java.time.LocalDate;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.format.DateTimeParseException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@ApplicationScoped
|
||||
public class ReleaseGroupRepository {
|
||||
@@ -29,6 +32,25 @@ public class ReleaseGroupRepository {
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void replaceForArtist(String mbid, List<ReleaseGroupBrowseResult.ReleaseGroupDto> newDtos) {
|
||||
FollowedArtist artist = FollowedArtist.findByMbid(mbid);
|
||||
if (artist == null) {
|
||||
return;
|
||||
}
|
||||
Set<String> newMbids = new HashSet<>();
|
||||
for (ReleaseGroupBrowseResult.ReleaseGroupDto rg : newDtos) {
|
||||
newMbids.add(rg.id);
|
||||
upsertOne(artist, rg);
|
||||
}
|
||||
List<ReleaseGroupEntity> existing = ReleaseGroupEntity.list("artist", artist);
|
||||
for (ReleaseGroupEntity rg : existing) {
|
||||
if (!newMbids.contains(rg.mbid)) {
|
||||
rg.delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void markSynced(String mbid) {
|
||||
FollowedArtist artist = FollowedArtist.findByMbid(mbid);
|
||||
|
||||
@@ -10,6 +10,8 @@ import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.enterprise.event.Observes;
|
||||
import jakarta.inject.Inject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.Executors;
|
||||
@@ -109,7 +111,28 @@ public class SyncService {
|
||||
}
|
||||
|
||||
public void resyncArtist(String mbid) {
|
||||
repo.deleteByArtistMbid(mbid);
|
||||
syncArtist(mbid);
|
||||
syncing.add(mbid);
|
||||
try {
|
||||
Set<String> enabledTypes = artistService.enabledTypes(mbid);
|
||||
String typeFilter = enabledTypes.isEmpty() ? null : String.join("|", enabledTypes);
|
||||
|
||||
List<ReleaseGroupBrowseResult.ReleaseGroupDto> all = new ArrayList<>();
|
||||
int limit = 100;
|
||||
int offset = 0;
|
||||
boolean more = true;
|
||||
while (more) {
|
||||
ReleaseGroupBrowseResult page = mbzService.browseReleaseGroups(mbid, typeFilter, limit, offset);
|
||||
if (page == null || page.releaseGroups == null || page.releaseGroups.isEmpty()) {
|
||||
break;
|
||||
}
|
||||
all.addAll(page.releaseGroups);
|
||||
offset += page.releaseGroups.size();
|
||||
more = page.releaseGroups.size() == limit && offset < page.count;
|
||||
}
|
||||
repo.replaceForArtist(mbid, all);
|
||||
repo.markSynced(mbid);
|
||||
} finally {
|
||||
syncing.remove(mbid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user