feat: Enhance user metrics retrieval by integrating Extraction model and updating related queries
This commit is contained in:
@@ -17,6 +17,7 @@ from app.models.credit_transaction import CreditTransaction
|
||||
from app.models.playlist import Playlist
|
||||
from app.models.sound import Sound
|
||||
from app.models.tts import TTS
|
||||
from app.models.extraction import Extraction
|
||||
from app.repositories.base import BaseRepository
|
||||
|
||||
logger = get_logger(__name__)
|
||||
@@ -262,19 +263,19 @@ class UserRepository(BaseRepository[User]):
|
||||
query = query.where(CreditTransaction.created_at >= date_filter)
|
||||
|
||||
elif metric_type == "tracks_added":
|
||||
# Get users with most EXT sounds added
|
||||
# Get users with most EXT sounds added (via extractions)
|
||||
query = (
|
||||
select(
|
||||
User.id,
|
||||
User.name,
|
||||
func.count(Sound.id).label("count")
|
||||
func.count(Extraction.id).label("count")
|
||||
)
|
||||
.join(Sound, User.id == Sound.user_id)
|
||||
.where(Sound.type == "EXT")
|
||||
.join(Extraction, User.id == Extraction.user_id)
|
||||
.where(Extraction.sound_id.is_not(None)) # Only count successful extractions
|
||||
.group_by(User.id, User.name)
|
||||
)
|
||||
if date_filter:
|
||||
query = query.where(Sound.created_at >= date_filter)
|
||||
query = query.where(Extraction.created_at >= date_filter)
|
||||
|
||||
elif metric_type == "tts_added":
|
||||
# Get users with most TTS sounds added
|
||||
|
||||
Reference in New Issue
Block a user