Skip to content

Commit

Permalink
added pagination to message query
Browse files Browse the repository at this point in the history
This will allow the client to refresh the view during long query and also throttle it to avoid starving other clients
  • Loading branch information
tzachshabtay committed Oct 23, 2020
1 parent 31306c3 commit 801930a
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions src/client/kafka/messages/single_topic_input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,33 @@ export class SingleTopicInput extends React.Component<Props, State> {
this.setState({ loadingMessages: true })
this.props.onDataFetchStarted()
const topic = this.props.topic
const response = await fetch(`/api/messages/${topic}/${this.state.partition}?limit=${this.state.limit}&offset=${this.state.offset}&search=${this.props.search}&timeout=${timeout}`)
const data = await response.json()
this.props.onDataFetched(data)
let cursor = this.state.offset
const end = cursor + this.state.limit
let out: any = null
let limit = this.state.limit
if (limit > 1000) {
limit = 1000
}
while (cursor < end) {
const response = await fetch(`/api/messages/${topic}/${this.state.partition}?limit=${limit}&offset=${cursor}&search=${this.props.search}&timeout=${timeout}`)
cursor += limit
const data = await response.json()
if (!out) {
out = data
} else if (data.messages) {
out.messages = [...out.messages, ...data.messages]
}
if (data.error) {
out.error = data.error
}
if (data.hasTimeout) {
out.hasTimeout = data.hasTimeout
}
this.props.onDataFetched(out)
if (out.error || out.hasTimeout) {
break
}
}
this.setState({loadingMessages: false})
}

Expand Down

0 comments on commit 801930a

Please sign in to comment.