maquinaweb-shared-auth 0.2.28__py3-none-any.whl → 0.2.29__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of maquinaweb-shared-auth might be problematic. Click here for more details.
- {maquinaweb_shared_auth-0.2.28.dist-info → maquinaweb_shared_auth-0.2.29.dist-info}/METADATA +1 -1
- {maquinaweb_shared_auth-0.2.28.dist-info → maquinaweb_shared_auth-0.2.29.dist-info}/RECORD +5 -5
- shared_auth/managers.py +47 -9
- {maquinaweb_shared_auth-0.2.28.dist-info → maquinaweb_shared_auth-0.2.29.dist-info}/WHEEL +0 -0
- {maquinaweb_shared_auth-0.2.28.dist-info → maquinaweb_shared_auth-0.2.29.dist-info}/top_level.txt +0 -0
|
@@ -5,7 +5,7 @@ shared_auth/conf.py,sha256=WlSXQB7p3BfE3BL6WR6EDYpCHQEjDlxQlyf8dTfClsk,621
|
|
|
5
5
|
shared_auth/decorators.py,sha256=RT-Qfi7oGBo6PvWJRR1dqJUQdU6ZOf9p-8mV3rZmqQ0,3237
|
|
6
6
|
shared_auth/exceptions.py,sha256=VKamHjBl2yjXG2RsMrLrXru1_Q9IJXmy4xmDcXlpWsU,627
|
|
7
7
|
shared_auth/fields.py,sha256=RAcmFh1D_nkbai_7t_OrPZhfhAipesy5kKnEj4LUvvM,1254
|
|
8
|
-
shared_auth/managers.py,sha256=
|
|
8
|
+
shared_auth/managers.py,sha256=WB0tU3asVxwS4tFq2R9-zXtWMBpvOuM94_SehGbVQFw,8268
|
|
9
9
|
shared_auth/middleware.py,sha256=72GF8kGijbhw98v2Q-1sXBXk-7Bamfyvypm9h8xLX_I,6112
|
|
10
10
|
shared_auth/mixins.py,sha256=BSYNTWYjLRGuxfy7x-uAaNZmrTMsm67ogAQzjrU2DoQ,7388
|
|
11
11
|
shared_auth/models.py,sha256=vCyssDwKfWRE3ofl6LK_CB1-y5O-_6uvJyGZGoCnb44,6574
|
|
@@ -15,7 +15,7 @@ shared_auth/serializers.py,sha256=VmajFqnAHB5wyxsdd5_WVegAQygi0KNOMk7vScCPHiQ,73
|
|
|
15
15
|
shared_auth/storage_backend.py,sha256=Eqkjz8aF5UrOpRwYl-J0Td95IObfxnJ8eLQDJVFM3Io,184
|
|
16
16
|
shared_auth/urls.py,sha256=591wWEWJPaHEGkcOZ8yvfgxddRyOcZLgOc0vNtF7XRI,289
|
|
17
17
|
shared_auth/views.py,sha256=2hyLnYSWUscfq-jVcskt-ukzDt4vg6IXeKjRDRu9RXk,1519
|
|
18
|
-
maquinaweb_shared_auth-0.2.
|
|
19
|
-
maquinaweb_shared_auth-0.2.
|
|
20
|
-
maquinaweb_shared_auth-0.2.
|
|
21
|
-
maquinaweb_shared_auth-0.2.
|
|
18
|
+
maquinaweb_shared_auth-0.2.29.dist-info/METADATA,sha256=0zltusF9fsm1p4ldeM4su1hxpCactgoNbIFQZhDQEJM,26331
|
|
19
|
+
maquinaweb_shared_auth-0.2.29.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
20
|
+
maquinaweb_shared_auth-0.2.29.dist-info/top_level.txt,sha256=msyYRy02ZV7zz7GR1raUI5LXGFIFn2TIkgkeKZqKufE,12
|
|
21
|
+
maquinaweb_shared_auth-0.2.29.dist-info/RECORD,,
|
shared_auth/managers.py
CHANGED
|
@@ -89,13 +89,27 @@ class OrganizationQuerySetMixin:
|
|
|
89
89
|
|
|
90
90
|
def with_organization_data(self):
|
|
91
91
|
"""
|
|
92
|
-
Pré-carrega dados de organizações (evita N+1)
|
|
92
|
+
Pré-carrega dados de organizações (evita N+1 queries)
|
|
93
|
+
|
|
94
|
+
Faz uma única query bulk para buscar todas as organizações necessárias
|
|
95
|
+
e cacheia nos objetos usando _cached_organization.
|
|
96
|
+
|
|
97
|
+
Usage:
|
|
98
|
+
# Sem otimização (N+1 queries)
|
|
99
|
+
rascunhos = Rascunho.objects.all()
|
|
100
|
+
for r in rascunhos:
|
|
101
|
+
print(r.organization.name) # Query individual para cada
|
|
102
|
+
|
|
103
|
+
# Com otimização (2 queries total)
|
|
104
|
+
rascunhos = Rascunho.objects.all().with_organization_data()
|
|
105
|
+
for r in rascunhos:
|
|
106
|
+
print(r.organization.name) # Usa cache, sem queries extras
|
|
93
107
|
|
|
94
108
|
Returns:
|
|
95
109
|
Lista de objetos com _cached_organization
|
|
96
110
|
"""
|
|
97
111
|
objects = list(self.all())
|
|
98
|
-
from . import SharedOrganization
|
|
112
|
+
from .models import SharedOrganization
|
|
99
113
|
|
|
100
114
|
if not objects:
|
|
101
115
|
return objects
|
|
@@ -128,9 +142,15 @@ class UserQuerySetMixin:
|
|
|
128
142
|
|
|
129
143
|
def with_user_data(self):
|
|
130
144
|
"""
|
|
131
|
-
Pré-carrega dados de usuários (evita N+1)
|
|
145
|
+
Pré-carrega dados de usuários (evita N+1 queries)
|
|
146
|
+
|
|
147
|
+
Usage:
|
|
148
|
+
# Com otimização (2 queries total)
|
|
149
|
+
rascunhos = Rascunho.objects.all().with_user_data()
|
|
150
|
+
for r in rascunhos:
|
|
151
|
+
print(r.user.email) # Usa cache, sem queries extras
|
|
132
152
|
"""
|
|
133
|
-
from . import
|
|
153
|
+
from .models import User
|
|
134
154
|
|
|
135
155
|
objects = list(self.all())
|
|
136
156
|
|
|
@@ -139,7 +159,7 @@ class UserQuerySetMixin:
|
|
|
139
159
|
|
|
140
160
|
user_ids = set(obj.user_id for obj in objects)
|
|
141
161
|
|
|
142
|
-
users = {user.pk: user for user in
|
|
162
|
+
users = {user.pk: user for user in User.objects.filter(pk__in=user_ids)}
|
|
143
163
|
|
|
144
164
|
for obj in objects:
|
|
145
165
|
obj._cached_user = users.get(obj.user_id)
|
|
@@ -152,9 +172,27 @@ class OrganizationUserQuerySetMixin(OrganizationQuerySetMixin, UserQuerySetMixin
|
|
|
152
172
|
|
|
153
173
|
def with_auth_data(self):
|
|
154
174
|
"""
|
|
155
|
-
Pré-carrega dados de organizações E usuários (evita N+1)
|
|
175
|
+
Pré-carrega dados de organizações E usuários (evita N+1 queries)
|
|
176
|
+
|
|
177
|
+
Faz apenas 3 queries no total, independente da quantidade de objetos:
|
|
178
|
+
1. Query dos objetos principais
|
|
179
|
+
2. Query bulk das organizações
|
|
180
|
+
3. Query bulk dos usuários
|
|
181
|
+
|
|
182
|
+
Usage:
|
|
183
|
+
# Sem otimização (1 + N + N queries)
|
|
184
|
+
rascunhos = Rascunho.objects.all() # 1 query
|
|
185
|
+
for r in rascunhos:
|
|
186
|
+
print(r.organization.name) # N queries
|
|
187
|
+
print(r.user.email) # N queries
|
|
188
|
+
|
|
189
|
+
# Com otimização (3 queries total)
|
|
190
|
+
rascunhos = Rascunho.objects.all().with_auth_data()
|
|
191
|
+
for r in rascunhos:
|
|
192
|
+
print(r.organization.name) # Cache
|
|
193
|
+
print(r.user.email) # Cache
|
|
156
194
|
"""
|
|
157
|
-
from . import SharedOrganization,
|
|
195
|
+
from .models import SharedOrganization, User
|
|
158
196
|
|
|
159
197
|
objects = list(self.all())
|
|
160
198
|
|
|
@@ -170,7 +208,7 @@ class OrganizationUserQuerySetMixin(OrganizationQuerySetMixin, UserQuerySetMixin
|
|
|
170
208
|
org.pk: org for org in SharedOrganization.objects.filter(pk__in=org_ids)
|
|
171
209
|
}
|
|
172
210
|
|
|
173
|
-
users = {user.pk: user for user in
|
|
211
|
+
users = {user.pk: user for user in User.objects.filter(pk__in=user_ids)}
|
|
174
212
|
|
|
175
213
|
# Cachear
|
|
176
214
|
for obj in objects:
|
|
@@ -183,7 +221,7 @@ class OrganizationUserQuerySetMixin(OrganizationQuerySetMixin, UserQuerySetMixin
|
|
|
183
221
|
"""
|
|
184
222
|
Cria objeto com validação de organização e usuário
|
|
185
223
|
"""
|
|
186
|
-
from . import SharedMember, SharedOrganization
|
|
224
|
+
from .models import SharedMember, SharedOrganization
|
|
187
225
|
|
|
188
226
|
# Valida organização
|
|
189
227
|
SharedOrganization.objects.get_or_fail(organization_id)
|
|
File without changes
|
{maquinaweb_shared_auth-0.2.28.dist-info → maquinaweb_shared_auth-0.2.29.dist-info}/top_level.txt
RENAMED
|
File without changes
|