Friday, July 27, 2018

Re: avoiding import-time queries

I've been experimenting with it and it seems to be working pretty well. Thank you, Julio!

On Thursday, July 26, 2018 at 2:28:18 PM UTC-4, Julio Biason wrote:
Hi Clarvierplayer,

Dunno if that's a best practice, but I'd add a module in the same app with functions to retrieve the information and use cache (https://docs.djangoproject.com/en/2.0/topics/cache/#basic-usage) copiously. So, instead of loading the values at start up time, the values would be filled only after the first time it was requested.

On Thu, Jul 26, 2018 at 3:21 PM, <clavie...@gmail.com> wrote:
I'm looking for some best-practice (or at least workable) suggestions for avoiding import-time queries. I have some database records that are constant, and these constants are used all over the application. Is there any way to get those constants out of the database once at startup? 

At present, I am working on a set of apps with a single underlying database. And they wouldn't build at all when I tried to migrate a new test database because of import-time queries, because it wants to validate the references to those constants at build time (and can't, because in this case my new test database has no tables yet). Is there any way to store these model records in something that will persist between builds (kind of like test fixtures)? A StackOverflow discussion suggested the Python Lazy Object Proxy, but that project appears to have been abandoned. The Django docs themselves simply recommend avoiding query-at-import behaviors--I can definitely see it causes all kinds of problems that are not easy to circumvent--but they make no recommendations for alternatives. Is it indeed necessary to keep querying for these all over the app? Is there a third-party solution that I've overlooked?

Django 2.0. Thank you!

--
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...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/9510552d-9afe-47b0-842e-6f80e9a28bbe%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Julio Biason, Sofware Engineer
AZION  |  Deliver. Accelerate. Protect.
Office: +55 51 3083 8101  |  Mobile: +55 51 99907 0554

--
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+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/b487bf9d-359c-4541-82a9-2b6228fe9437%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment