Skip to content

Commit

Permalink
fix(topicdata): search can failed data pagination with many results (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexisSouquiere authored Apr 26, 2023
1 parent 07c486d commit 4713261
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
9 changes: 5 additions & 4 deletions client/src/containers/Topic/Topic/TopicData/TopicData.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -183,15 +183,13 @@ class TopicData extends Root {
this.eventSource.addEventListener('searchBody', function (e) {
const res = JSON.parse(e.data);
const records = res.records || [];
const nextPage = res.after ? res.after : self.state.nextPage;

const percentDiff = res.percent - lastPercentVal;

// to avoid UI slowdowns, only update the percentage in fixed increments
if (percentDiff >= percentUpdateDelta) {
lastPercentVal = res.percent;
self.setState({
nextPage,
recordCount: self.state.recordCount + records.length,
percent: res.percent.toFixed(2)
});
Expand All @@ -207,9 +205,12 @@ class TopicData extends Root {
}
});

this.eventSource.addEventListener('searchEnd', function () {
this.eventSource.addEventListener('searchEnd', function (e) {
const res = JSON.parse(e.data);
const nextPage = res.after ? res.after : self.state.nextPage;
self.setState({ percent: 100, nextPage, isSearching: false, loading: false });

self.eventSource.close();
self.setState({ percent: 100, isSearching: false, loading: false });
});
}
);
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/org/akhq/repositories/RecordRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -683,8 +683,7 @@ public Flowable<Event<SearchEvent>> search(Topic topic, Options options) throws

// end
if (searchEvent == null || searchEvent.emptyPoll == 666) {

emitter.onNext(new SearchEvent(topic).end());
emitter.onNext(new SearchEvent(topic).end(searchEvent != null ? searchEvent.after: null));
emitter.onComplete();
consumer.close();

Expand Down Expand Up @@ -725,7 +724,7 @@ public Flowable<Event<SearchEvent>> search(Topic topic, Options options) throws

if (currentEvent.emptyPoll >= 1) {
currentEvent.emptyPoll = 666;
emitter.onNext(currentEvent.end());
emitter.onNext(currentEvent.end(searchEvent.getAfter()));
} else if (matchesCount.get() >= options.getSize()) {
currentEvent.emptyPoll = 666;
emitter.onNext(currentEvent.progress(options));
Expand Down Expand Up @@ -860,8 +859,9 @@ private SearchEvent(Topic topic) {
});
}

public Event<SearchEvent> end() {
public Event<SearchEvent> end(String after) {
this.percent = 100;
this.after = after;

return Event.of(this).name("searchEnd");
}
Expand Down

0 comments on commit 4713261

Please sign in to comment.