forked from Archives/Athou_commafeed
the "new-feed-entries" websocket event no longer needs to reload the entire tree
This commit is contained in:
@@ -118,7 +118,7 @@ public class FeedRefreshUpdater {
|
||||
|
||||
public boolean update(Feed feed, List<Entry> entries) {
|
||||
boolean processed = true;
|
||||
boolean insertedAtLeastOneEntry = false;
|
||||
long inserted = 0;
|
||||
|
||||
if (!entries.isEmpty()) {
|
||||
Set<String> lastEntries = cache.getLastEntries(feed);
|
||||
@@ -134,7 +134,7 @@ public class FeedRefreshUpdater {
|
||||
}
|
||||
AddEntryResult addEntryResult = addEntry(feed, entry, subscriptions);
|
||||
processed &= addEntryResult.processed;
|
||||
insertedAtLeastOneEntry |= addEntryResult.inserted;
|
||||
inserted += addEntryResult.inserted ? 1 : 0;
|
||||
|
||||
entryCacheMiss.mark();
|
||||
} else {
|
||||
@@ -148,13 +148,12 @@ public class FeedRefreshUpdater {
|
||||
|
||||
if (subscriptions == null) {
|
||||
feed.setMessage("No new entries found");
|
||||
} else if (insertedAtLeastOneEntry) {
|
||||
} else if (inserted > 0) {
|
||||
List<User> users = subscriptions.stream().map(FeedSubscription::getUser).toList();
|
||||
cache.invalidateUnreadCount(subscriptions.toArray(new FeedSubscription[0]));
|
||||
cache.invalidateUserRootCategory(users.toArray(new User[0]));
|
||||
|
||||
// notify over websocket
|
||||
subscriptions.forEach(sub -> webSocketSessions.sendMessage(sub.getUser(), WebSocketMessageBuilder.newFeedEntries(sub)));
|
||||
notifyOverWebsocket(subscriptions, inserted);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -163,7 +162,7 @@ public class FeedRefreshUpdater {
|
||||
feed.setDisabledUntil(Instant.EPOCH);
|
||||
}
|
||||
|
||||
if (insertedAtLeastOneEntry) {
|
||||
if (inserted > 0) {
|
||||
feedUpdated.mark();
|
||||
}
|
||||
|
||||
@@ -172,6 +171,10 @@ public class FeedRefreshUpdater {
|
||||
return processed;
|
||||
}
|
||||
|
||||
private void notifyOverWebsocket(List<FeedSubscription> subscriptions, long inserted) {
|
||||
subscriptions.forEach(sub -> webSocketSessions.sendMessage(sub.getUser(), WebSocketMessageBuilder.newFeedEntries(sub, inserted)));
|
||||
}
|
||||
|
||||
@AllArgsConstructor
|
||||
private static class AddEntryResult {
|
||||
private final boolean processed;
|
||||
|
||||
@@ -7,8 +7,8 @@ import lombok.experimental.UtilityClass;
|
||||
@UtilityClass
|
||||
public class WebSocketMessageBuilder {
|
||||
|
||||
public static String newFeedEntries(FeedSubscription subscription) {
|
||||
return String.format("%s:%s", "new-feed-entries", subscription.getId());
|
||||
public static String newFeedEntries(FeedSubscription subscription, long count) {
|
||||
return String.format("%s:%s:%s", "new-feed-entries", subscription.getId(), count);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user