Skip to content

Commit

Permalink
fix(postgres/feature-analytics): use feature filter (#3091)
Browse files Browse the repository at this point in the history
  • Loading branch information
gagantrivedi committed Dec 5, 2023
1 parent 1065ad0 commit c0fc231
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
1 change: 1 addition & 0 deletions api/app_analytics/analytics_db_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ def get_feature_evaluation_data_from_local_db(
FeatureEvaluationBucket.objects.filter(
environment_id=environment_id,
bucket_size=ANALYTICS_READ_BUCKET_SIZE,
feature_name=feature.name,
created_at__date__lte=timezone.now(),
created_at__date__gt=timezone.now() - timedelta(days=period),
)
Expand Down
3 changes: 2 additions & 1 deletion api/app_analytics/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ def check_overlapping_buckets(self, filters):

if overlapping_buckets.exists():
raise ValidationError(
"Cannot create bucket starting at {self.created_at} with size {self.bucket_size} minutes,"
"Cannot create bucket starting at %s with size %s minutes,"
"because it overlaps with existing buckets"
% (self.created_at, self.bucket_size),
)


Expand Down
17 changes: 16 additions & 1 deletion api/tests/unit/app_analytics/test_analytics_db_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
)
from django.conf import settings
from django.utils import timezone
from pytest_django.fixtures import SettingsWrapper

from environments.models import Environment
from features.models import Feature


@pytest.mark.skipif(
Expand Down Expand Up @@ -138,7 +142,9 @@ def test_get_total_events_count(organisation, environment, settings):
reason="Skip test if analytics database is configured",
)
@pytest.mark.django_db(databases=["analytics", "default"])
def test_get_feature_evaluation_data_from_local_db(feature, environment, settings):
def test_get_feature_evaluation_data_from_local_db(
feature: Feature, environment: Environment, settings: SettingsWrapper
):
environment_id = environment.id
feature_name = feature.name
now = timezone.now()
Expand Down Expand Up @@ -181,6 +187,15 @@ def test_get_feature_evaluation_data_from_local_db(feature, environment, setting
created_at=now - timedelta(days=i),
)

# some data for different feature
FeatureEvaluationBucket.objects.create(
environment_id=environment_id,
feature_name="some_other_feature",
total_count=10,
bucket_size=read_bucket_size,
created_at=now - timedelta(days=i),
)

# When
usage_data_list = get_feature_evaluation_data_from_local_db(feature, environment_id)

Expand Down

3 comments on commit c0fc231

@vercel
Copy link

@vercel vercel bot commented on c0fc231 Dec 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on c0fc231 Dec 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on c0fc231 Dec 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

docs – ./docs

docs-flagsmith.vercel.app
docs-git-main-flagsmith.vercel.app
docs.flagsmith.com
docs.bullet-train.io

Please sign in to comment.