Skip to content

feat: get plan bulk with cache#10

Open
tomerqodo wants to merge 4 commits intoaugment_full_base_feat_get_plan_bulk_with_cache_pr10from
augment_full_head_feat_get_plan_bulk_with_cache_pr10
Open

feat: get plan bulk with cache#10
tomerqodo wants to merge 4 commits intoaugment_full_base_feat_get_plan_bulk_with_cache_pr10from
augment_full_head_feat_get_plan_bulk_with_cache_pr10

Conversation

@tomerqodo
Copy link
Copy Markdown

Benchmark PR from agentic-review-benchmarks#10

@augmentcode
Copy link
Copy Markdown

augmentcode Bot commented Jan 26, 2026

🤖 Augment PR Summary

Summary: Adds a Redis-backed cache layer for bulk subscription plan retrieval to reduce load on the billing API.

Changes:

  • Introduced Redis key prefix/TTL constants and a helper to build tenant plan cache keys
  • Implemented get_plan_bulk_with_cache() which performs Redis mget for cache hits, then falls back to get_plan_bulk() for misses
  • Writes fetched plans back to Redis using a pipeline and setex with a 10-minute TTL
  • Hardened get_plan_bulk() to log and handle per-tenant validation failures
  • Added container-based integration tests covering hit/miss behavior, Redis failures, invalid cache data, and TTL expiration
  • Added unit test coverage for handling invalid tenant plan payloads

Technical Notes: Cache entries are stored as JSON blobs in Redis and validated via Pydantic TypeAdapter(SubscriptionPlan) on read.

🤖 Was this summary useful? React with 👍 or 👎

Copy link
Copy Markdown

@augmentcode augmentcode Bot left a comment

Choose a reason for hiding this comment

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

Review completed. 4 suggestions posted.

Fix All in Augment

Comment augment review to trigger a new review at any time.

plan: str
expiration_date: int

def __str__(self) -> str:
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

TypedDict definitions don’t support instance methods; adding __str__ here can raise a TypeError at import/class-creation time and prevent the module from loading.

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎

logger.exception(
"get_plan_bulk: failed to validate subscription plan for tenant(%s)", tenant_id
)
results[tenant_id] = None
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

get_plan_bulk() is annotated/documented as returning SubscriptionPlan values, but this stores None on validation failure; downstream code/tests expecting missing tenants (or dict-like plans) will break.

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎

plans_to_cache: dict[str, SubscriptionPlan] = {}

for tenant_id, subscription_plan in bulk_plans.items():
tenant_plans[tenant_id] = subscription_plan
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

get_plan_bulk_with_cache() copies subscription_plan values from get_plan_bulk() into tenant_plans (and then Redis); if any value is None, it will be serialized (e.g., as null) and later fail schema validation, causing repeated cache misses and potential None values in the returned mapping.

Other Locations
  • api/services/billing_service.py:376

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎

"""Clean up Redis cache before and after each test."""
with flask_app_with_containers.app_context():
# Clean up before test
yield
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This fixture docstring says it cleans Redis “before and after”, but currently the cleanup happens only after yield; if any prior test left tenant_plan:* keys around, these tests can become order-dependent/flaky.

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎

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.

3 participants