News for hackers. Stuff that matters.

Suor

Re:Ban 1+N in Django on Monday March 27, 2023 @10:36AM (#35327202)
Writing things directly is tightly coupling code. Sometimes quite distant portions of it, i.e. database access and presentation logic. With ORM and some smarter lazy technics or introspection at least you can untie it, with hand written SQL there is no way. And the reason is strings are poorly composable. Unless you use some query generator, but then we are back to ORM-like something.
Re:Ban 1+N in Django on Monday March 27, 2023 @07:01AM (#35325130)
Never used this, but I see that it provides a context manager/decorator, which you can use to "shield" any code. And also some shortcuts for DjangoREST or something.

Regarding extra code, you can simply replace the Djangos' `render()`, with the one from this lib and you are done. I would have probably made a custom template extension or something to do that for all renders automatically though too.

Re:Ban 1+N in Django on Monday March 27, 2023 @06:58AM (#35325105)
cacheops is more of a general purpose ORM caching with automatic invalidation.
Re:Ban 1+N in Django on Sunday March 26, 2023 @11:53PM (#35322678)
For that fetching in chunks is usually a way to go. I use something of these usually https://handy.readthedocs.io/en/latest/db.html#queryset_iter...
Re:Ban 1+N in Django on Sunday March 26, 2023 @11:36PM (#35322580)
GraphQL makes it even more fun :)
Re:Ban 1+N in Django on Sunday March 26, 2023 @09:12PM (#35321704)
I usually use `.values()` and `.values_list()` only when model creation is really slow. Usually many rows fetched.
Re:Ban 1+N in Django on Sunday March 26, 2023 @08:55PM (#35321555)
Actually there is such thing already https://pypi.org/project/django-auto-prefetch/ Not a monkey patch though, so will only work on the models you inherit from this.
Re:Ban 1+N in Django on Sunday March 26, 2023 @08:51PM (#35321537)
Re:Ban 1+N in Django on Sunday March 26, 2023 @08:49PM (#35321523)
Should be easy enough to implement. You only need a context manager that adds 1 to some threadlocal flag on enter and subrracts on exit then check this flag in the monkey patch. Not sure how costly that will be though.
Re:Ban 1+N in Django on Sunday March 26, 2023 @08:44PM (#35321476)
cacheops can do the same, but it never came to my mind to actually go this way. I would rather write some special code to fetch with `id__in=[...]` and then cache individually.
Re:Ban 1+N in Django on Sunday March 26, 2023 @09:40AM (#35314339)
HN keeps automatically replacing the URL. It used to be a redirect before, but not anymore
Re:Ban 1+N in Django on Sunday March 26, 2023 @09:25AM (#35314190)
Thanks
Re:Boiling React Down to Few Lines in JQuery on Sunday March 08, 2015 @09:52PM (#9168483)
Using framework has its cost, so you can be better of if you understand clearly what you are doing. OTOH, framework brings structure so it's less probable you skrew up your design.
Re:Boiling React Down to Few Lines in JQuery on Sunday March 08, 2015 @09:49PM (#9168473)
There are sure some things I haven't covered. The major one is components, which make a big deal in factor, reuse and composition. But the post started to be too long and loosing point so I skipped it.

There are also ideas beyond React I left aside. I will probably write some follow up post later.

Re:Ask HN: Why my link disappeared from HN? on Sunday March 08, 2015 @12:27PM (#9166077)
I've already emailed there, won't make a difference probably anyway. I hate this HN tricky rating, one my post got dumped from top 5 cause there were too many comments!

Reddit kind of saves the day :)

Re:Ask HN: Why my link disappeared from HN? on Sunday March 08, 2015 @11:43AM (#9165911)
I announced on twitter and posted to reddit. Is this prohibited?
Re:Ask HN: Why my link disappeared from HN? on Sunday March 08, 2015 @11:36AM (#9165882)
Maybe english?
Re:Ask HN: Why my link disappeared from HN? on Sunday March 08, 2015 @11:36AM (#9165881)
Is there something wrong with it?

Older ยป