Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Conversation

preyunk
Copy link
Contributor

@preyunk preyunk commented Jan 29, 2024

Add stream API to stream data for a large number of results, this can be controlled by chunk_size query parameter, the server will sleep for 1 second when it has yieled chunk_size data. The server needs to sleep for 1 second since it needs time to gather the records (chunk_size).

Add stream API to stream data for a large number of results,
this can be controlled by chunk_size query parameter,
the server will sleep for 1 second when it has yieled `chunk_size` data.
The server needs to sleep for 1 second since it needs time to gather the records (chunk_size).

Signed-off-by: Priyank Singh <[email protected]>
@preyunk preyunk requested a review from piyusql January 29, 2024 15:33
# SPDX-License-Identifier: BSD-2-Clause

import json
import time
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// TODO remove this import

Copy link
Contributor

@piyusql piyusql left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix as per the reviews.


@method_decorator(require_http_methods(['GET']), name='dispatch')
class StreamView(View):
STREAM_SEPERATOR = '$$'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A simple comma will also work to make every dict a row.

return bool(set(self.params.fields).intersection(
self.model_config.get_properties()))

def _get_model_fields(self, row):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change the method name to _get_model_row_dict to make it more readable.

# handle values case where property is passed in fields
if qset_opt == 'values' and self.query_has_properties():
if qset_opt == 'values' and stream:
return self.yield_fields()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's reform this to make a unified approach b/w return and non-return for each method, in this case this is being a special case here to return generator.
One more point regrading count query which is being evaluated after values operator, if count option is passed, stream will beof no use and should be set to False.

self.qset = self.model_config.model.objects.using(
self.params.db_name).filter(query.Q)
else:
self.qset = self.model_config.model.objects.filter(query.Q)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

handle the stream part using self.yqset

use stream as a query parameter in read, this gives the flexibility to
ignore stream if count or some other paramter is present

Signed-off-by: Priyank Singh <[email protected]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants