Skip to content

Stream state more efficient loading of subjects #1179

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

Merged
merged 2 commits into from
Jul 11, 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
14 changes: 11 additions & 3 deletions src/main/java/io/nats/client/api/StreamState.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import io.nats.client.support.JsonValue;

import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -48,13 +49,20 @@ public class StreamState {
lastTime = readDate(vStreamState, LAST_TS);
subjectCount = readLong(vStreamState, NUM_SUBJECTS, 0);
deletedCount = readLong(vStreamState, NUM_DELETED, 0);
subjects = Subject.listOf(readValue(vStreamState, SUBJECTS));
deletedStreamSequences = readLongList(vStreamState, DELETED);
lostStreamData = LostStreamData.optionalInstance(readValue(vStreamState, LOST));

subjects = new ArrayList<>();
subjectMap = new HashMap<>();
for (Subject s : subjects) {
subjectMap.put(s.getName(), s.getCount());
JsonValue vSubjects = readValue(vStreamState, SUBJECTS);
if (vSubjects != null && vSubjects.map != null) {
for (String subject : vSubjects.map.keySet()) {
Long count = getLong(vSubjects.map.get(subject));
if (count != null) {
subjects.add(new Subject(subject, count));
subjectMap.put(subject, count);
}
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/nats/client/api/Subject.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ static List<Subject> listOf(JsonValue vSubjects) {
return list;
}

private Subject(String name, long count) {
public Subject(String name, long count) {
this.name = name;
this.count = count;
}
Expand Down
Loading