feat: get plan bulk with cache#95
Conversation
Greptile SummaryThis PR adds a new
Issues requiring attention:
Confidence Score: 2/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant Client
participant BillingService
participant Redis
participant BillingAPI
Client->>BillingService: get_plan_bulk_with_cache(tenant_ids)
BillingService->>Redis: mget(cache_keys)
alt All Cache Hits
Redis-->>BillingService: cached plans
BillingService-->>Client: tenant_plans
else Partial/Full Cache Miss
Redis-->>BillingService: partial/empty results
BillingService->>BillingAPI: get_plan_bulk(missing_ids)
BillingAPI-->>BillingService: subscription plans
BillingService->>Redis: pipeline.setex(plans, TTL=600)
BillingService-->>Client: merged tenant_plans
else Redis Failure
Redis-->>BillingService: Exception
BillingService->>BillingAPI: get_plan_bulk(all_tenant_ids)
BillingAPI-->>BillingService: subscription plans
BillingService->>Redis: pipeline.setex(plans, TTL=600)
BillingService-->>Client: tenant_plans
end
|
| def __str__(self) -> str: | ||
| """Return a human-readable string representation for debugging.""" | ||
| return f"Plan: {self['plan']}, Expiration: {self['expiration_date']}" |
There was a problem hiding this comment.
logic: TypedDict is just a dict at runtime - methods defined in the class body are ignored. This __str__ method will never be called on SubscriptionPlan instances.
| def __str__(self) -> str: | |
| """Return a human-readable string representation for debugging.""" | |
| return f"Plan: {self['plan']}, Expiration: {self['expiration_date']}" |
Prompt To Fix With AI
This is a comment left during a code review.
Path: api/services/billing_service.py
Line: 28:30
Comment:
**logic:** `TypedDict` is just a dict at runtime - methods defined in the class body are ignored. This `__str__` method will never be called on `SubscriptionPlan` instances.
```suggestion
```
How can I resolve this? If you propose a fix, please make it concise.| logger.exception( | ||
| "get_plan_bulk: failed to validate subscription plan for tenant(%s)", tenant_id | ||
| ) | ||
| results[tenant_id] = None |
There was a problem hiding this comment.
logic: Assigning None violates the return type dict[str, SubscriptionPlan]. Either update the return type to dict[str, SubscriptionPlan | None] or skip adding the key entirely by using continue instead.
| results[tenant_id] = None | |
| continue |
Prompt To Fix With AI
This is a comment left during a code review.
Path: api/services/billing_service.py
Line: 292:292
Comment:
**logic:** Assigning `None` violates the return type `dict[str, SubscriptionPlan]`. Either update the return type to `dict[str, SubscriptionPlan | None]` or skip adding the key entirely by using `continue` instead.
```suggestion
continue
```
How can I resolve this? If you propose a fix, please make it concise.| assert len(result) == 2 | ||
| assert "tenant-valid-1" in result | ||
| assert "tenant-valid-2" in result | ||
| assert "tenant-invalid" not in result |
There was a problem hiding this comment.
logic: These assertions contradict the actual code behavior. The code at line 292 sets results[tenant_id] = None for invalid tenants, so len(result) will be 3 (not 2) and "tenant-invalid" will be in the result (with None value). Fix the production code or update these assertions.
Prompt To Fix With AI
This is a comment left during a code review.
Path: api/tests/unit_tests/services/test_billing_service.py
Line: 1316:1319
Comment:
**logic:** These assertions contradict the actual code behavior. The code at line 292 sets `results[tenant_id] = None` for invalid tenants, so `len(result)` will be 3 (not 2) and `"tenant-invalid"` will be in the result (with `None` value). Fix the production code or update these assertions.
How can I resolve this? If you propose a fix, please make it concise.
Benchmark PR from qodo-benchmark#445