Comments (3)
Hello, I'm sorry you are running into this issue. Off the top of my head, I wonder if this is an n+1
problem? You don't show the query for filtered_object_list
, but you might be able to put a select_related
or prefetch_related
which would reduce subsequent foreign-key lookups. Although based on your statement that you have tried "changing Django models to simple objects" this might not solve your problem.
One thing to see what might be going on is to change the Unicorn
component to a regular Django include
and output the same model data. If it's still slow, it's an ORM issue. If it's super fast, then there might be something going on in Unicorn
.
I render a component for every row in a table in this example: https://github.com/adamghill/django-unicorn/blob/main/example/unicorn/templates/unicorn/nested/table.html#L38. The backend code is here: https://github.com/adamghill/django-unicorn/blob/main/example/unicorn/components/nested/table.py#L31. You can see I have a select_related
to prevent duplicate database queries. I just tested it with 100 rows and it still renders very quickly, so hopefully tweaking the ORM query will work for you as well!
There should be minimal overhead when rendering components with Unicorn
, but If the above doesn't work, please let me know.
from django-unicorn.
Hi,
Thank you very much for your quick reply. Forgive me, I forgot to include that filtered_object_list
is basically a converted QuerySet
of projects
to a list of objects of type "AvailableProjectPresenter" in a way:
context['filtered_object_list'] = [
AvailableProjectPresenter(project, ...) for project in Project.objects.select_related(...).prefetch_related(...).filter(...).annotate(...)
]
Unfortunately, we are sure that this is not an N+1
problem because:
- we are already using
select_related
andprefetch_related
and we use it on the correct fields - we tested this problem on simplified queries without using any related models
- in the template we only changed
{% include ... %}
to{% unicorn ... %}
and this increased the number of queries from 55 to 685 (of which almost 95% were duplicates) and the wait time increased from~800ms
to~11s
- according to django-debug-toolbar every database query called in our template is duplicated, not only the
Project.objects...
query, but also other queries used in the template
We suspect it may be a problem with the way components render themselves and the use of beautifulsoup4 to find a component's parent, but we haven't been able to test that yet.
from django-unicorn.
Ah, thanks for the further clarification here -- that is frustrating! I'm going to try to replicate your set up in the example app in this repo to see if I get the same results. Or let me know if there is a minimal way to reproduce, thanks.
from django-unicorn.
Related Issues (20)
- HTML select "IndexError: tuple index out of range" when using custom setter with "$event.target.value" HOT 1
- Bug: unicorn:poll throwing error HOT 2
- Incorrect Variable Passed Turned into String? HOT 3
- Morphdom Exception: component.js:257 TypeError: Cannot read properties of undefined (reading 'nodeType') HOT 3
- UnicornView._attribute_names() fails in some components because of unresolved type hints HOT 5
- Float in nested tuple[dict] gets converted to string HOT 2
- Using requests library inside of a UnicornView HOT 1
- Lists of Dataclass or Pydantic objects don't seem to serialize/deserialize properly.. HOT 1
- Cannot redirect from mount()
- feature request: make `self.request` available within `javascript_exclude` class properties HOT 10
- handling non-standard django app configs HOT 2
- parent components (i) do not refresh children html and (ii) break when used as direct views HOT 15
- updating child components via a parent method HOT 1
- Combining ```unicorn:view``` and ```unicorn:poll``` features gives error ```The 'control' component appears to have multiple root elements.``` HOT 1
- ValueError after second post HOT 3
- possible race condition: `unicorn:model` looses data when saved too quickly. HOT 1
- self.parent reference not updating
- Force rendering parent doesn't run context processors
- Search Example: Error Checksum when setting component value HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from django-unicorn.