maquinaweb-shared-auth 0.2.28__py3-none-any.whl → 0.2.30__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.30.dist-info}/METADATA +1 -1
- {maquinaweb_shared_auth-0.2.28.dist-info → maquinaweb_shared_auth-0.2.30.dist-info}/RECORD +6 -6
- shared_auth/managers.py +88 -19
- shared_auth/mixins.py +1 -0
- {maquinaweb_shared_auth-0.2.28.dist-info → maquinaweb_shared_auth-0.2.30.dist-info}/WHEEL +0 -0
- {maquinaweb_shared_auth-0.2.28.dist-info → maquinaweb_shared_auth-0.2.30.dist-info}/top_level.txt +0 -0
|
@@ -5,9 +5,9 @@ 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=A9y-X4ixVXhsNxgr3YD4DtuN4ufrX7LbM_JPwJ0Y3aA,9176
|
|
9
9
|
shared_auth/middleware.py,sha256=72GF8kGijbhw98v2Q-1sXBXk-7Bamfyvypm9h8xLX_I,6112
|
|
10
|
-
shared_auth/mixins.py,sha256=
|
|
10
|
+
shared_auth/mixins.py,sha256=9TJk07hlHXnTYu0tPNr7VAXd7VL9fyXayMaFERifLLY,7389
|
|
11
11
|
shared_auth/models.py,sha256=vCyssDwKfWRE3ofl6LK_CB1-y5O-_6uvJyGZGoCnb44,6574
|
|
12
12
|
shared_auth/permissions.py,sha256=FNIp12ePOUlXVp26zNMAyEtzX9kwyP7RuNIgaaCXtPA,2671
|
|
13
13
|
shared_auth/router.py,sha256=zYidJ7j40lQLrhkCtAQAp-rQLhua_UF0X7SDzYRcV5w,668
|
|
@@ -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.30.dist-info/METADATA,sha256=bIuaOJDn7kPoK8tE16uQWf3qgqPO3RixJpJ9HiYYXUk,26331
|
|
19
|
+
maquinaweb_shared_auth-0.2.30.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
20
|
+
maquinaweb_shared_auth-0.2.30.dist-info/top_level.txt,sha256=msyYRy02ZV7zz7GR1raUI5LXGFIFn2TIkgkeKZqKufE,12
|
|
21
|
+
maquinaweb_shared_auth-0.2.30.dist-info/RECORD,,
|
shared_auth/managers.py
CHANGED
|
@@ -89,16 +89,38 @@ 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
|
+
IMPORTANTE: Este método força a avaliação do QuerySet e aplica cache.
|
|
98
|
+
Para manter a chain de QuerySet, chame este método por último.
|
|
99
|
+
|
|
100
|
+
Usage:
|
|
101
|
+
# Sem otimização (N+1 queries)
|
|
102
|
+
rascunhos = Rascunho.objects.all()
|
|
103
|
+
for r in rascunhos:
|
|
104
|
+
print(r.organization.name) # Query individual para cada
|
|
105
|
+
|
|
106
|
+
# Com otimização (2 queries total)
|
|
107
|
+
rascunhos = Rascunho.objects.all().with_organization_data()
|
|
108
|
+
for r in rascunhos:
|
|
109
|
+
print(r.organization.name) # Usa cache, sem queries extras
|
|
93
110
|
|
|
94
111
|
Returns:
|
|
95
|
-
|
|
112
|
+
Self (QuerySet) com _prefetch_done=True e objetos cacheados
|
|
96
113
|
"""
|
|
97
|
-
|
|
98
|
-
|
|
114
|
+
# Marcar que o prefetch foi feito
|
|
115
|
+
self._prefetch_done = True
|
|
116
|
+
|
|
117
|
+
# Forçar avaliação do queryset
|
|
118
|
+
objects = list(self)
|
|
99
119
|
|
|
100
120
|
if not objects:
|
|
101
|
-
return
|
|
121
|
+
return self
|
|
122
|
+
|
|
123
|
+
from .models import SharedOrganization
|
|
102
124
|
|
|
103
125
|
# Coletar IDs únicos
|
|
104
126
|
org_ids = set(obj.organization_id for obj in objects)
|
|
@@ -112,7 +134,10 @@ class OrganizationQuerySetMixin:
|
|
|
112
134
|
for obj in objects:
|
|
113
135
|
obj._cached_organization = organizations.get(obj.organization_id)
|
|
114
136
|
|
|
115
|
-
|
|
137
|
+
# Armazenar os objetos cacheados no queryset
|
|
138
|
+
self._result_cache = objects
|
|
139
|
+
|
|
140
|
+
return self
|
|
116
141
|
|
|
117
142
|
|
|
118
143
|
class UserQuerySetMixin:
|
|
@@ -128,23 +153,39 @@ class UserQuerySetMixin:
|
|
|
128
153
|
|
|
129
154
|
def with_user_data(self):
|
|
130
155
|
"""
|
|
131
|
-
Pré-carrega dados de usuários (evita N+1)
|
|
156
|
+
Pré-carrega dados de usuários (evita N+1 queries)
|
|
157
|
+
|
|
158
|
+
Usage:
|
|
159
|
+
# Com otimização (2 queries total)
|
|
160
|
+
rascunhos = Rascunho.objects.all().with_user_data()
|
|
161
|
+
for r in rascunhos:
|
|
162
|
+
print(r.user.email) # Usa cache, sem queries extras
|
|
163
|
+
|
|
164
|
+
Returns:
|
|
165
|
+
Self (QuerySet) com objetos cacheados
|
|
132
166
|
"""
|
|
133
|
-
from . import
|
|
167
|
+
from .models import User
|
|
168
|
+
|
|
169
|
+
# Marcar que o prefetch foi feito
|
|
170
|
+
self._prefetch_done = True
|
|
134
171
|
|
|
135
|
-
|
|
172
|
+
# Forçar avaliação do queryset
|
|
173
|
+
objects = list(self)
|
|
136
174
|
|
|
137
175
|
if not objects:
|
|
138
|
-
return
|
|
176
|
+
return self
|
|
139
177
|
|
|
140
178
|
user_ids = set(obj.user_id for obj in objects)
|
|
141
179
|
|
|
142
|
-
users = {user.pk: user for user in
|
|
180
|
+
users = {user.pk: user for user in User.objects.filter(pk__in=user_ids)}
|
|
143
181
|
|
|
144
182
|
for obj in objects:
|
|
145
183
|
obj._cached_user = users.get(obj.user_id)
|
|
146
184
|
|
|
147
|
-
|
|
185
|
+
# Armazenar os objetos cacheados no queryset
|
|
186
|
+
self._result_cache = objects
|
|
187
|
+
|
|
188
|
+
return self
|
|
148
189
|
|
|
149
190
|
|
|
150
191
|
class OrganizationUserQuerySetMixin(OrganizationQuerySetMixin, UserQuerySetMixin):
|
|
@@ -152,14 +193,39 @@ class OrganizationUserQuerySetMixin(OrganizationQuerySetMixin, UserQuerySetMixin
|
|
|
152
193
|
|
|
153
194
|
def with_auth_data(self):
|
|
154
195
|
"""
|
|
155
|
-
Pré-carrega dados de organizações E usuários (evita N+1)
|
|
196
|
+
Pré-carrega dados de organizações E usuários (evita N+1 queries)
|
|
197
|
+
|
|
198
|
+
Faz apenas 3 queries no total, independente da quantidade de objetos:
|
|
199
|
+
1. Query dos objetos principais
|
|
200
|
+
2. Query bulk das organizações
|
|
201
|
+
3. Query bulk dos usuários
|
|
202
|
+
|
|
203
|
+
Usage:
|
|
204
|
+
# Sem otimização (1 + N + N queries)
|
|
205
|
+
rascunhos = Rascunho.objects.all() # 1 query
|
|
206
|
+
for r in rascunhos:
|
|
207
|
+
print(r.organization.name) # N queries
|
|
208
|
+
print(r.user.email) # N queries
|
|
209
|
+
|
|
210
|
+
# Com otimização (3 queries total)
|
|
211
|
+
rascunhos = Rascunho.objects.all().with_auth_data()
|
|
212
|
+
for r in rascunhos:
|
|
213
|
+
print(r.organization.name) # Cache
|
|
214
|
+
print(r.user.email) # Cache
|
|
215
|
+
|
|
216
|
+
Returns:
|
|
217
|
+
Self (QuerySet) com objetos cacheados
|
|
156
218
|
"""
|
|
157
|
-
from . import SharedOrganization,
|
|
219
|
+
from .models import SharedOrganization, User
|
|
158
220
|
|
|
159
|
-
|
|
221
|
+
# Marcar que o prefetch foi feito
|
|
222
|
+
self._prefetch_done = True
|
|
223
|
+
|
|
224
|
+
# Forçar avaliação do queryset
|
|
225
|
+
objects = list(self)
|
|
160
226
|
|
|
161
227
|
if not objects:
|
|
162
|
-
return
|
|
228
|
+
return self
|
|
163
229
|
|
|
164
230
|
# Coletar IDs
|
|
165
231
|
org_ids = set(obj.organization_id for obj in objects)
|
|
@@ -170,20 +236,23 @@ class OrganizationUserQuerySetMixin(OrganizationQuerySetMixin, UserQuerySetMixin
|
|
|
170
236
|
org.pk: org for org in SharedOrganization.objects.filter(pk__in=org_ids)
|
|
171
237
|
}
|
|
172
238
|
|
|
173
|
-
users = {user.pk: user for user in
|
|
239
|
+
users = {user.pk: user for user in User.objects.filter(pk__in=user_ids)}
|
|
174
240
|
|
|
175
241
|
# Cachear
|
|
176
242
|
for obj in objects:
|
|
177
243
|
obj._cached_organization = organizations.get(obj.organization_id)
|
|
178
244
|
obj._cached_user = users.get(obj.user_id)
|
|
179
245
|
|
|
180
|
-
|
|
246
|
+
# Armazenar os objetos cacheados no queryset
|
|
247
|
+
self._result_cache = objects
|
|
248
|
+
|
|
249
|
+
return self
|
|
181
250
|
|
|
182
251
|
def create_with_validation(self, organization_id, user_id, **kwargs):
|
|
183
252
|
"""
|
|
184
253
|
Cria objeto com validação de organização e usuário
|
|
185
254
|
"""
|
|
186
|
-
from . import SharedMember, SharedOrganization
|
|
255
|
+
from .models import SharedMember, SharedOrganization
|
|
187
256
|
|
|
188
257
|
# Valida organização
|
|
189
258
|
SharedOrganization.objects.get_or_fail(organization_id)
|
shared_auth/mixins.py
CHANGED
|
@@ -227,6 +227,7 @@ class LoggedOrganizationMixin(viewsets.ModelViewSet):
|
|
|
227
227
|
return queryset.none()
|
|
228
228
|
|
|
229
229
|
organization_id = self.get_organization_id()
|
|
230
|
+
|
|
230
231
|
if hasattr(queryset.model, "organization_id"):
|
|
231
232
|
return queryset.filter(organization_id=organization_id)
|
|
232
233
|
elif hasattr(queryset.model, "organization"):
|
|
File without changes
|
{maquinaweb_shared_auth-0.2.28.dist-info → maquinaweb_shared_auth-0.2.30.dist-info}/top_level.txt
RENAMED
|
File without changes
|