mirror of
https://github.com/django/django.git
synced 2025-12-23 09:19:27 +00:00
Refs #36605 -- Optimized QuerySet.in_bulk() for the empty id_list case.
Some checks failed
Linters / flake8 (push) Waiting to run
Linters / isort (push) Waiting to run
Linters / black (push) Waiting to run
Tests / Windows, SQLite, Python 3.13 (push) Waiting to run
Tests / JavaScript tests (push) Waiting to run
Docs / spelling (push) Has been cancelled
Docs / blacken-docs (push) Has been cancelled
Docs / lint-docs (push) Has been cancelled
Some checks failed
Linters / flake8 (push) Waiting to run
Linters / isort (push) Waiting to run
Linters / black (push) Waiting to run
Tests / Windows, SQLite, Python 3.13 (push) Waiting to run
Tests / JavaScript tests (push) Waiting to run
Docs / spelling (push) Has been cancelled
Docs / blacken-docs (push) Has been cancelled
Docs / lint-docs (push) Has been cancelled
Now that the setup is a bit more expensive, it makes sense to return earlier for the empty case.
This commit is contained in:
parent
1820d35b17
commit
46bd92274c
1 changed files with 2 additions and 2 deletions
|
|
@ -1166,6 +1166,8 @@ class QuerySet(AltersData):
|
|||
"""
|
||||
if self.query.is_sliced:
|
||||
raise TypeError("Cannot use 'limit' or 'offset' with in_bulk().")
|
||||
if id_list is not None and not id_list:
|
||||
return {}
|
||||
opts = self.model._meta
|
||||
unique_fields = [
|
||||
constraint.fields[0]
|
||||
|
|
@ -1236,8 +1238,6 @@ class QuerySet(AltersData):
|
|||
)
|
||||
|
||||
if id_list is not None:
|
||||
if not id_list:
|
||||
return {}
|
||||
filter_key = "{}__in".format(field_name)
|
||||
id_list = tuple(id_list)
|
||||
batch_size = connections[self.db].ops.bulk_batch_size([opts.pk], id_list)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue