Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Don't evaluate default_timezone unless needed#8531

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged

Conversation

stianjensen
Copy link
Contributor

If you set a custom timezone for a DateTimeField, the function
self.default_timezone() is still called, since fallback params to
getattr are still evaluated.

This rewrites to use hasattr, so the fallback case is only executed if
it will actually be used. If you render a lot of DateTimeFields in a
serializer, the time spent evaluating default_timezone() once for each
of them can accumulate to quite a bit, which is just unused work in the
case where timezone is already specified on the field.

If you set a custom timezone for a DateTimeField, the functionself.default_timezone() is still called, since fallback params togetattr are still evaluated.This rewrites to use hasattr, so the fallback case is only executed ifit will actually be used. If you render a lot of DateTimeFields in aserializer, the time spent evaluating default_timezone() once for eachof them can accumulate to quite a bit, which is just unused work in thecase where timezone is already specified on the field.
Copy link
Member

@tomchristietomchristie left a comment

Choose a reason for hiding this comment

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

I don't have any objection to this.

@tomchristietomchristie merged commitdba9493 intoencode:masterJun 24, 2022
@stianjensenstianjensen deleted the lazy-default-timezone branchJune 24, 2022 10:29
sigvef pushed a commit to sigvef/django-rest-framework that referenced this pull requestDec 3, 2022
If you set a custom timezone for a DateTimeField, the functionself.default_timezone() is still called, since fallback params togetattr are still evaluated.This rewrites to use hasattr, so the fallback case is only executed ifit will actually be used. If you render a lot of DateTimeFields in aserializer, the time spent evaluating default_timezone() once for eachof them can accumulate to quite a bit, which is just unused work in thecase where timezone is already specified on the field.
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@tomchristietomchristietomchristie approved these changes

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants
@stianjensen@tomchristie

[8]ページ先頭

©2009-2025 Movatter.jp