partitioning.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. from dateutil.relativedelta import relativedelta
  2. from django.conf import settings
  3. from apps.issue_events.models import IssueEvent, IssueTag
  4. from apps.projects.models import (
  5. IssueEventProjectHourlyStatistic,
  6. TransactionEventProjectHourlyStatistic,
  7. )
  8. # from apps.performance_events import TransactionGroup
  9. from psqlextra.partitioning import (
  10. PostgresCurrentTimePartitioningStrategy,
  11. PostgresPartitioningManager,
  12. PostgresTimePartitionSize,
  13. )
  14. from psqlextra.partitioning.config import PostgresPartitioningConfig
  15. issue_strategy = PostgresCurrentTimePartitioningStrategy(
  16. size=PostgresTimePartitionSize(days=1),
  17. count=7,
  18. max_age=relativedelta(days=settings.GLITCHTIP_MAX_EVENT_LIFE_DAYS),
  19. )
  20. # transaction_strategy = PostgresCurrentTimePartitioningStrategy(
  21. # size=PostgresTimePartitionSize(days=1),
  22. # count=7,
  23. # max_age=relativedelta(days=settings.GLITCHTIP_MAX_TRANSACTION_EVENT_LIFE_DAYS),
  24. # )
  25. project_stat_strategy = PostgresCurrentTimePartitioningStrategy(
  26. size=PostgresTimePartitionSize(weeks=1),
  27. count=4,
  28. max_age=relativedelta(days=settings.GLITCHTIP_MAX_EVENT_LIFE_DAYS * 4),
  29. )
  30. manager = PostgresPartitioningManager(
  31. [
  32. PostgresPartitioningConfig(model=IssueEvent, strategy=issue_strategy),
  33. PostgresPartitioningConfig(model=IssueTag, strategy=issue_strategy),
  34. # PostgresPartitioningConfig(
  35. # model=TransactionGroup, strategy=transaction_strategy
  36. # ),
  37. PostgresPartitioningConfig(
  38. model=IssueEventProjectHourlyStatistic, strategy=project_stat_strategy
  39. ),
  40. PostgresPartitioningConfig(
  41. model=TransactionEventProjectHourlyStatistic, strategy=project_stat_strategy
  42. ),
  43. ]
  44. )