Skip to content

refactor(feed): Simplify promo feed logic and related views #61

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

Merged
merged 2 commits into from
Jul 22, 2025

Conversation

RandomProgramm3r
Copy link
Owner

This commit refactors the promo feed generation and comment handling to improve code structure, efficiency, and maintainability.

Key changes:

  • Moved the complex feed generation logic from UserFeedView into a new PromoManager.get_feed_for_user method. This centralizes business logic in the manager layer, simplifying the view and making the query logic reusable.
  • The new manager method encapsulates filtering for active promos and targeting by user age and country.
  • Optimized category filtering to use a direct __icontains database query, which is more efficient than the previous Python-based filtering.
  • Introduced a PromoObjectMixin to reduce code duplication in comment-related views (PromoCommentListCreateView, PromoCommentDetailView) by abstracting the common task of retrieving the associated promo object.

This commit refactors the promo feed generation and comment handling to improve code structure, efficiency, and maintainability.

Key changes:
 - Moved the complex feed generation logic from `UserFeedView` into a new `PromoManager.get_feed_for_user` method. This centralizes business logic in the manager layer, simplifying the view and making the query logic reusable.
- The new manager method encapsulates filtering for active promos and targeting by user age and country.
- Optimized category filtering to use a direct `__icontains` database query, which is more efficient than the previous Python-based filtering.
- Introduced a `PromoObjectMixin` to reduce code duplication in comment-related views (`PromoCommentListCreateView`, `PromoCommentDetailView`) by abstracting the common task of retrieving the associated promo object.
@RandomProgramm3r RandomProgramm3r merged commit 0f1ac9d into main Jul 22, 2025
2 checks passed
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