collab: Adapt rate limits based on plan (#15548)
This PR updates the rate limits to adapt based on the user's current plan. For the free plan rate limits I just took one-tenth of the existing rate limits (which are now the Pro limits). We can adjust, as needed. Release Notes: - N/A --------- Co-authored-by: Max <max@zed.dev>
This commit is contained in:
parent
7a0149f17c
commit
8c54a46202
5 changed files with 195 additions and 106 deletions
|
@ -110,13 +110,15 @@ impl Database {
|
|||
.await
|
||||
}
|
||||
|
||||
/// Returns all of the active billing subscriptions for the user with the specified ID.
|
||||
pub async fn get_active_billing_subscriptions(
|
||||
&self,
|
||||
user_id: UserId,
|
||||
) -> Result<Vec<billing_subscription::Model>> {
|
||||
/// Returns whether the user has an active billing subscription.
|
||||
pub async fn has_active_billing_subscription(&self, user_id: UserId) -> Result<bool> {
|
||||
Ok(self.count_active_billing_subscriptions(user_id).await? > 0)
|
||||
}
|
||||
|
||||
/// Returns the count of the active billing subscriptions for the user with the specified ID.
|
||||
pub async fn count_active_billing_subscriptions(&self, user_id: UserId) -> Result<usize> {
|
||||
self.transaction(|tx| async move {
|
||||
let subscriptions = billing_subscription::Entity::find()
|
||||
let count = billing_subscription::Entity::find()
|
||||
.inner_join(billing_customer::Entity)
|
||||
.filter(
|
||||
billing_customer::Column::UserId.eq(user_id).and(
|
||||
|
@ -124,11 +126,10 @@ impl Database {
|
|||
.eq(StripeSubscriptionStatus::Active),
|
||||
),
|
||||
)
|
||||
.order_by_asc(billing_subscription::Column::Id)
|
||||
.all(&*tx)
|
||||
.count(&*tx)
|
||||
.await?;
|
||||
|
||||
Ok(subscriptions)
|
||||
Ok(count as usize)
|
||||
})
|
||||
.await
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue