feat: align members table 'Last active' with active user billing definition#28003
Draft
sean-brydon wants to merge 2 commits intomainfrom
Draft
feat: align members table 'Last active' with active user billing definition#28003sean-brydon wants to merge 2 commits intomainfrom
sean-brydon wants to merge 2 commits intomainfrom
Conversation
…nition Replace User.lastActiveAt (only tracks hosting) with computed last active date from bookings, matching the billing definition where 'active' means hosted or attended at least one ACCEPTED booking. Changes: - Add getLastActiveAt to ActiveUserBillingRepository (queries most recent accepted booking as host or attendee) - Create CachedActiveUserBillingRepository with @memoize for Redis caching - Wire up DI (tokens, module, container) - Update teams and orgs listMembers handlers to use new logic - Add unit tests for the new repository method Co-Authored-By: sean@cal.com <Sean@brydon.io>
Contributor
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
Co-Authored-By: sean@cal.com <Sean@brydon.io>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
The "Last active" column in team/org members tables previously used
User.lastActiveAt, which only tracked when a user last hosted a new booking. This didn't match the active user billing definition, where "active" means the user hosted or attended at least one ACCEPTED booking.This PR replaces the static DB field with a computed value that queries the most recent accepted booking where the user was either host or attendee, cached via the
@MemoizeRedis decorator.Changes:
getLastActiveAt(userId, email)toActiveUserBillingRepository— parallel queries for latest accepted booking as host + attendee, returns the more recentCachedActiveUserBillingRepositorywrapping the method with@Memoize(cache key:active-user-billing:lastActive:{userId}, default 5min TTL)teams/listMembers.handler.tsandorganizations/listMembers.handler.tsto use the cached repository instead ofUser.lastActiveAtlastActiveAtfrom the Prismaselectin both handlers since it's now computedActiveUserBillingServicetest mock to include the new methodLink to Devin run: https://app.devin.ai/sessions/ac1b1321f14f4d6d93342a73ac3b30b8
Requested by: @sean-brydon
Mandatory Tasks (DO NOT REMOVE)
How should this be tested?
active-user-billing:lastActive:{userId}after loading members listEnvironment variables: None required beyond standard Cal.com setup
Human Review Checklist
Critical:
lastActiveAtFilter(~line 121 inorganizations/listMembers.handler.ts) still builds a Prismawhereclause onUser.lastActiveAt(the old DB column), but the displayed value now uses the new computed logic. Filtering by "Last active" date range will return results based on the old definition. Should this filter be removed, or is a follow-up needed to reconcile it?Important:
getLastActiveAtqueries the most recent accepted booking ever. This is intentional for "Last active" display, but worth confirming this is the desired behavior.active-user-billing:lastActive:{userId}(email not included). If a user changes email, stale attendee data is served until TTL expires (5min). Is this acceptable?User.lastActiveAtis still being written byRegularBookingServicebut is no longer read by these handlers. Should it be deprecated/removed in a follow-up?Nice to have:
@Memoizedecorator's default 5min TTL is appropriate for this use caseChecklist