Using generators in Django

Chris Angelico rosuav at gmail.com
Thu Dec 19 01:57:22 EST 2019


On Thu, Dec 19, 2019 at 5:34 PM onlinejudge95 <onlinejudge95 at gmail.com> wrote:
>
> Hi Devs,
>
> A quick question. I am using Django to schedule some commands to populate
> my PostgreSQL(Apart from using it as a web framework). I am currently
> fetching records from a particular table and for each of those records
> doing some calculation and storing the processed data in some other
> database. The skeleton code looks like this
>
>
> I need to know whether the use of generators is correct here, in the sense
> that would it have any performance issues. The point that I am having
> trouble understanding is a comment on my code review.

Performance should be dominated by the database speed. Whether you use
a generator or not should be insignificant compared to the time taken
by Postgres itself to perform the transaction. This should be done as
a single transaction for reliability, and that also means that it will
be a single transaction for performance.

ChrisA


More information about the Python-list mailing list