Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Save Organization.available_features as a DB column #4426

Merged
merged 10 commits into from
May 24, 2021

Conversation

Twixes
Copy link
Member

@Twixes Twixes commented May 20, 2021

Changes

Closes #4408 (a prerequisite for PostHog/plugin-server#235).

Makes Organization.available_features a model field (Postgres column) instead of a dynamically calculated property. This way the features-determination logic only has to run occasionally, and the results are available in the database, so the plugin server can use them too.

The field is updated (with organization.update_available_features()) in the following circumstances:

  • when the server is started, all orgs at once – in case the predefined plans just changed
  • every hour half past the hour, all orgs at once – in case of subscription changes/license expiration, eventual consistency sort of
  • when a License instance is created/updated, all orgs at once – for private instances
  • when an OrganizationBilling instance is created/updated, only the relevant org – for Cloud (https://github.com/PostHog/posthog-cloud/pull/121)

Checklist

  • All querysets/queries filter by Organization, by Team, and by User
  • Django backend tests
  • Migrations are safe to run at scale (e.g. PostHog Cloud) – present proof if not obvious

Twixes added 2 commits May 20, 2021 19:39

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
@timgl timgl temporarily deployed to posthog-pr-4426 May 20, 2021 17:58 Inactive
@Twixes Twixes temporarily deployed to posthog-pr-4426 May 20, 2021 19:22 Inactive
@Twixes Twixes temporarily deployed to posthog-pr-4426 May 20, 2021 19:23 Inactive
@Twixes Twixes requested a review from paolodamico May 21, 2021 08:19
Copy link
Contributor

@paolodamico paolodamico left a comment

Choose a reason for hiding this comment

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

lgtm! minor comments

from posthog.models.organization import Organization


def sync_all_organization_available_features() -> None:
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: naming sync_all_organizations_available_features

Copy link
Member Author

Choose a reason for hiding this comment

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

This is more of "Sync all Organization.available_features", I think I'll leave as is

@receiver(models.signals.pre_save, sender=Organization)
def organization_about_to_be_created(sender, instance: Organization, raw, using, **kwargs):
if instance._state.adding:
instance.update_available_features()
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe worth just updating this particular org?

Copy link
Member Author

Choose a reason for hiding this comment

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

WDYM? That does seem to be the case already?

@Twixes Twixes temporarily deployed to posthog-pr-4426 May 24, 2021 16:33 Inactive
@Twixes Twixes temporarily deployed to posthog-pr-4426 May 24, 2021 16:38 Inactive
@Twixes Twixes temporarily deployed to posthog-pr-4426 May 24, 2021 17:49 Inactive
@Twixes Twixes temporarily deployed to posthog-pr-4426 May 24, 2021 19:37 Inactive
@Twixes Twixes merged commit eaf2459 into master May 24, 2021
@Twixes Twixes deleted the saved-available-features branch May 24, 2021 20:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make Organization.available_features available to the plugin server
3 participants