Skip to content

Comments

feat: add group filter to product and plan listing endpoints#735

Open
carlosmfreitas2409 wants to merge 1 commit intouseautumn:devfrom
carlosmfreitas2409:feat/group-filter
Open

feat: add group filter to product and plan listing endpoints#735
carlosmfreitas2409 wants to merge 1 commit intouseautumn:devfrom
carlosmfreitas2409:feat/group-filter

Conversation

@carlosmfreitas2409
Copy link

@carlosmfreitas2409 carlosmfreitas2409 commented Feb 12, 2026

Summary

Add group filter to product and plan listing endpoints — Both the public GET /plans and internal GET /products endpoints now accept an optional group query parameter, which filters products by their group field.

PR in SDK: useautumn/typescript#71

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Refactor
  • Other (please describe):

Checklist

  • I have read the CONTRIBUTING.md
  • My code follows the code style of this project
  • I have added tests where applicable
  • I have tested my changes locally
  • I have linked relevant issues
  • I have added screenshots for UI changes (if applicable)

Greptile Overview

Greptile Summary

Added optional group query parameter to product and plan listing endpoints, enabling filtering of products by their group field.

API changes

  • Public GET /plans endpoint now accepts optional group query parameter
  • Internal GET /products/products endpoint now accepts optional group query parameter

Improvements

  • Cache key generation updated to include group parameter in hash for cache differentiation
  • Database query filtering properly implements group-based filtering using Drizzle ORM

Bug fixes

  • Cache invalidation logic needs updating - currently doesn't clear group-filtered cache entries when products are modified (see inline comment)

Confidence Score: 3/5

  • This PR is safe to merge with moderate risk due to cache invalidation issue
  • The implementation correctly adds group filtering to the database queries and cache key generation. However, the cache invalidation mechanism in productCacheUtils.ts only handles archived parameter variants and doesn't account for group-filtered cache entries. This means when products are modified, stale cached data may persist for queries with specific group filters. The core functionality works correctly, but the caching issue could lead to data inconsistency until cache TTL expires (1 day).
  • Pay close attention to server/src/internal/products/ProductService.ts - the cache invalidation logic needs to be updated to handle group-filtered cache entries

Important Files Changed

Filename Overview
shared/api/products/crud/listPlanParams.ts Added optional group query parameter to ListPlansQuerySchema for filtering plans by group
server/src/internal/products/handlers/handleListPlans.ts Extracted group from query parameters and passed it to ProductService.listFull for filtering
server/src/internal/products/internalHandlers/handleGetProducts.ts Added group query parameter extraction and passed it to ProductService.listFull for internal products endpoint
server/src/internal/products/ProductService.ts Added group parameter to listFull and _listFullQuery methods with database filtering and cache key integration, but cache invalidation doesn't account for group-filtered cache entries

Sequence Diagram

sequenceDiagram
    participant Client
    participant handleListPlans
    participant ProductService
    participant Cache
    participant Database

    Client->>handleListPlans: GET /plans?group=premium
    handleListPlans->>ProductService: listFull({orgId, env, group: "premium"})
    
    ProductService->>ProductService: Check if canCache
    
    alt Can use cache
        ProductService->>Cache: buildProductsCacheKey({orgId, env, queryParams: {group}})
        Cache-->>ProductService: Cache key with group hash
        ProductService->>Cache: queryWithCache(key, fn)
        
        alt Cache hit
            Cache-->>ProductService: Cached products
        else Cache miss
            ProductService->>Database: _listFullQuery with group filter
            Database-->>ProductService: Filtered products
            ProductService->>Cache: Store with group-specific key
        end
    else Cannot use cache
        ProductService->>Database: _listFullQuery directly
        Database-->>ProductService: Filtered products
    end
    
    ProductService-->>handleListPlans: Products filtered by group
    handleListPlans-->>Client: JSON response with filtered plans
Loading

(3/5) Reply to the agent's comments like "Can you suggest a fix for this @greptileai?" or ask follow-up questions!

@vercel
Copy link

vercel bot commented Feb 12, 2026

@carlosmfreitas2409 is attempting to deploy a commit to the Autumn Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

No issues found across 4 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

4 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

Comment on lines 237 to +240
key: buildProductsCacheKey({
orgId,
env,
queryParams: { archived },
queryParams: { archived, group },
Copy link
Contributor

Choose a reason for hiding this comment

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

Cache invalidation in invalidateProductsCache() doesn't account for group-filtered cache entries. When products are modified, cached queries with different group parameter values won't be invalidated, leading to stale data.

The invalidateProductsCache() function in productCacheUtils.ts only invalidates cache keys for archived parameter variants, but now that group is part of the cache key hash, queries like ?group=premium will remain cached even after product updates.

Prompt To Fix With AI
This is a comment left during a code review.
Path: server/src/internal/products/ProductService.ts
Line: 237:240

Comment:
Cache invalidation in `invalidateProductsCache()` doesn't account for group-filtered cache entries. When products are modified, cached queries with different `group` parameter values won't be invalidated, leading to stale data.

The `invalidateProductsCache()` function in `productCacheUtils.ts` only invalidates cache keys for `archived` parameter variants, but now that `group` is part of the cache key hash, queries like `?group=premium` will remain cached even after product updates.

How can I resolve this? If you propose a fix, please make it concise.

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.

1 participant