When working with foreign keys, accessing the related field will result in a database read. That can be eliminated by using *_id
, which is the foreign key value that Django has already cached on the object to make this scenario more efficient.
If our GitHub code review bot spots this issue in your pull request it gives this advice:
1 | + | def trigger_tasks(queryset): | |
2 | + | for item in queryset: | |
3 | + | run_async_task(item.page.id) |
When working with foreign keys, accessing the related field will result in a database read. That can be eliminated by using *_id
, which is the foreign key value that Django has already cached on the object to make this scenario more efficient.
- | run_async_task(item.page.id) |
+ | run_async_task(item.page_id) |