Suggestion for prefetch_related() documentation

2022-06-23 Thread Laurent Lyaudet
Hello,

I made a simple test to check the number of queries done :

# First part
order = Order.objects.get(id=2)  # one query
items = list(order.items.all())  # one query
items = list(order.items.all())  # one query
items = list(order.items.all())  # one query

# Second part
order = Order.objects.prefetch_related("items").get(id=2)  # two queries
items = list(order.items.all())  # no query
items = list(order.items.all())  # no query
items = list(order.items.all())  # no query

# Third part
order = Order.objects.get(id=2)  # one query
prefetch_related_objects([order], "items")  # one query
items = list(order.items.all())  # no query
items = list(order.items.all())  # no query
items = list(order.items.all())  # no query
prefetch_related_objects([order], "items")  # no more query
prefetch_related_objects([order], "items")  # no more query

I was surprised that there was 4 queries for the First part of the test 
instead of 2 for the other parts, because I was expecting that .all() would 
also fill the cache and not only use it.
Maybe it is intended.
I think that this test or something else explaining this point could 
enhance the documentation on prefetch_related() and 
prefetch_related_objects().
I advised my colleagues to use prefetch_related_objects() when in doubt 
whether the objects given have been already extended with prefetching.

Best regards,
 Laurent Lyaudet




-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/806fd09c-b997-4a1d-91c0-9c4cf5860f2an%40googlegroups.com.


Re: Suggestion for prefetch_related() documentation

2022-06-25 Thread Laurent Lyaudet
Hello,

Thanks for the link :)
I think the documentation would be better structured, then, if
https://docs.djangoproject.com/fr/4.0/ref/models/querysets/ would
reference your link.

I have not read all of Django documentation.
I do not know if it is expected that most developers would read everything.
Hence, I learn using Google top ranked pages inside Django
documentation when I search for a narrow topic on Django.
If I search
django prefetch
django prefetching
django prefetch_related
django prefetch_related_objets
I have https://docs.djangoproject.com/fr/4.0/ref/models/querysets/ as
first result but your link does not appear.
If I search
django cache
django caching
I get this
https://docs.djangoproject.com/fr/4.0/topics/cache/
but also your link as the third answer of Google.
Maybe, adding a link to /topics/db/optimization from
ref/models/querysets/ would help Google and people like me find this
information more easily :)

Best regards,
Laurent Lyaudet


Le ven. 24 juin 2022 à 08:05, Jason  a écrit :
>
>
> This is explicitly called out in the documentation at 
> https://docs.djangoproject.com/en/4.0/topics/db/optimization/#understand-queryset-evaluation
> On Thursday, June 23, 2022 at 1:17:50 PM UTC-4 laurent...@gmail.com wrote:
>>
>> Hello,
>>
>> I made a simple test to check the number of queries done :
>>
>> # First part
>> order = Order.objects.get(id=2)  # one query
>> items = list(order.items.all())  # one query
>> items = list(order.items.all())  # one query
>> items = list(order.items.all())  # one query
>>
>> # Second part
>> order = Order.objects.prefetch_related("items").get(id=2)  # two queries
>> items = list(order.items.all())  # no query
>> items = list(order.items.all())  # no query
>> items = list(order.items.all())  # no query
>>
>> # Third part
>> order = Order.objects.get(id=2)  # one query
>> prefetch_related_objects([order], "items")  # one query
>> items = list(order.items.all())  # no query
>> items = list(order.items.all())  # no query
>> items = list(order.items.all())  # no query
>> prefetch_related_objects([order], "items")  # no more query
>> prefetch_related_objects([order], "items")  # no more query
>>
>> I was surprised that there was 4 queries for the First part of the test 
>> instead of 2 for the other parts, because I was expecting that .all() would 
>> also fill the cache and not only use it.
>> Maybe it is intended.
>> I think that this test or something else explaining this point could enhance 
>> the documentation on prefetch_related() and prefetch_related_objects().
>> I advised my colleagues to use prefetch_related_objects() when in doubt 
>> whether the objects given have been already extended with prefetching.
>>
>> Best regards,
>>  Laurent Lyaudet
>>
>>
>>
>>
> --
> You received this message because you are subscribed to a topic in the Google 
> Groups "Django users" group.
> To unsubscribe from this topic, visit 
> https://groups.google.com/d/topic/django-users/CLnzKAcrE-A/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to 
> django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/01353b97-2b21-4d52-aab7-3046f93a5e1dn%40googlegroups.com.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAB1LBmssEnOGAAiKJDdLbL226oguyryJTkMUsKNYLTg1%3D89Urg%40mail.gmail.com.


Is starting a i18n project to translate only the dates ?

2022-09-12 Thread Laurent Lyaudet
Hello,

Django defines some strings to translate even before any code is added in a 
django app.
Is there a default .po for these strings in various languages ?

I looked at the source code for date formating in Django on Github.
And it uses gettext to translate months for example :
https://github.com/django/django/blob/4d4bf55e0ea849476f7e3abfeb018c338f18a9b4/django/utils/dates.py#L24
It seems thus that a .po file is mandatory to have it in another language 
than English

Until now we formatted dates using python (and probably python uses system 
locales).
I wanted to use Django features instead but it seems to be quite cumbersome 
to start an i18n project just for dates translations.

Thanks, best regards,
 Laurent Lyaudet


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/159f660c-49c2-443a-b496-d3aca4c6e6c7n%40googlegroups.com.