Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add premium user check in celery task #2668

Merged
merged 2 commits into from
Jun 13, 2024
Merged

Conversation

StanGirard
Copy link
Collaborator

"This pull request adds a new celery task called check_if_is_premium_user that checks if a user is a premium user based on their subscription status. The task retrieves the list of active subscriptions and the list of customers from the Supabase database. It then matches the subscriptions with the customers and updates the user settings with the corresponding premium features if a match is found. If a user is not found or their subscription is expired, the user settings are deleted. This task will run periodically to keep the user settings up to date with the subscription status.

Copy link

vercel bot commented Jun 12, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
quivrapp ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 12, 2024 10:52pm

@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. area: backend Related to backend functionality or under the /backend directory labels Jun 12, 2024
@StanGirard StanGirard changed the title "feat: Add premium user check in celery task" feat: Add premium user check in celery task Jun 12, 2024
Copy link

sonarcloud bot commented Jun 12, 2024

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

Copy link
Collaborator

@AmineDiro AmineDiro left a comment

Choose a reason for hiding this comment

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

will greatly improve latency on chat routes ! 👍🏼

Comments about future optimizations and some logic on the user_settings delete

if subscription["customer"] == customer["id"]
]
logger.debug(f"Matching subscription: {matching_subscription}")
user_id = (
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could be a join on the customer<->user on the email so we can get all at the same time. Not critical for now! maybe just a TODO 😄

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not possible with supabase without a foreign key. Being foreign table I can't do that

.execute()
).data
if len(user_settings) > 0:
supabase_db.table("user_settings").delete().match(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Small question here if len(match_subscription) == 0 do we delete the row or update the is_premium to False ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm deleting the row because then when the user ask a new question it will insert with the models, questions and all by default. Otherwise I have to look for the default value of the db manually

Copy link
Collaborator

Choose a reason for hiding this comment

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

❤️

@StanGirard StanGirard merged commit ec58935 into main Jun 13, 2024
4 checks passed
@StanGirard StanGirard deleted the feat/improve-time-premium branch June 13, 2024 08:14
StanGirard added a commit that referenced this pull request Jun 13, 2024
🤖 I have created a release *beep* *boop*
---


## 0.0.264 (2024-06-13)

## What's Changed
* fix: name passed in sync authorize by @StanGirard in
#2665
* feat: Add premium user check in celery task by @StanGirard in
#2668


**Full Changelog**:
v0.0.263...v0.0.264

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: backend Related to backend functionality or under the /backend directory size:L This PR changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants