1
- # -*- coding: utf-8 -*-
2
- from __future__ import unicode_literals
3
-
4
1
import logging
5
2
import typing
6
3
from copy import deepcopy
7
4
8
5
from core .models import abstract_base_auditable_model_factory
9
6
from core .request_origin import RequestOrigin
7
+ from django .apps import apps
10
8
from django .conf import settings
11
9
from django .contrib .contenttypes .fields import GenericRelation
12
10
from django .core .cache import caches
13
11
from django .db import models
14
- from django .db .models import Q
12
+ from django .db .models import Prefetch , Q
15
13
from django .utils import timezone
16
14
from django .utils .translation import ugettext_lazy as _
17
15
from django_lifecycle import (
36
34
generate_client_api_key ,
37
35
generate_server_api_key ,
38
36
)
37
+ from environments .constants import IDENTITY_INTEGRATIONS_RELATION_NAMES
39
38
from environments .dynamodb import (
40
39
DynamoEnvironmentAPIKeyWrapper ,
41
40
DynamoEnvironmentV2Wrapper ,
@@ -213,11 +212,7 @@ def get_from_cache(cls, api_key):
213
212
select_related_args = (
214
213
"project" ,
215
214
"project__organisation" ,
216
- "mixpanel_config" ,
217
- "segment_config" ,
218
- "amplitude_config" ,
219
- "heap_config" ,
220
- "dynatrace_config" ,
215
+ * IDENTITY_INTEGRATIONS_RELATION_NAMES ,
221
216
)
222
217
base_qs = cls .objects .select_related (* select_related_args ).defer (
223
218
"description"
@@ -243,7 +238,10 @@ def write_environments_to_dynamodb(
243
238
Q (id = environment_id ) if environment_id else Q (project_id = project_id )
244
239
)
245
240
environments = list (
246
- cls .objects .filter_for_document_builder (environments_filter )
241
+ cls .objects .filter_for_document_builder (
242
+ environments_filter ,
243
+ extra_select_related = IDENTITY_INTEGRATIONS_RELATION_NAMES ,
244
+ )
247
245
)
248
246
if not environments :
249
247
return
@@ -369,8 +367,21 @@ def _get_environment_document_from_db(
369
367
cls ,
370
368
api_key : str ,
371
369
) -> dict [str , typing .Any ]:
372
- environment = cls .objects .filter_for_document_builder (api_key = api_key ).get ()
373
- return map_environment_to_sdk_document (environment )
370
+ Identity = apps .get_model ("identities" , "Identity" )
371
+ environment = cls .objects .filter_for_document_builder (
372
+ api_key = api_key ,
373
+ extra_prefetch_related = [
374
+ Prefetch (
375
+ "identities" ,
376
+ queryset = Identity .objects .only_overrides (),
377
+ to_attr = "identities_with_overrides" ,
378
+ )
379
+ ],
380
+ ).get ()
381
+ return map_environment_to_sdk_document (
382
+ environment ,
383
+ identities_with_overrides = environment .identities_with_overrides ,
384
+ )
374
385
375
386
def _get_environment (self ):
376
387
return self
0 commit comments