[scrobbles] GeoLocations dont need to rebuild charts
This commit is contained in:
@ -5,7 +5,7 @@ from django.dispatch import receiver
|
||||
from django.utils import timezone
|
||||
|
||||
from scrobbles.models import Scrobble
|
||||
from scrobbles.tasks import MEDIA_TYPES, update_charts_for_timestamp
|
||||
from scrobbles.tasks import CHARTABLE_MEDIA_TYPES, SCROBBLES_WITHOUT_CHARTS, update_charts_for_timestamp
|
||||
from scrobbles.utils import tokenize_title_to_tags
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@ -19,7 +19,10 @@ def update_charts_on_scrobble_complete(sender, instance, **kwargs):
|
||||
if instance.timestamp is None:
|
||||
return
|
||||
|
||||
if instance.media_type.lower() not in MEDIA_TYPES:
|
||||
if instance.media_type.lower() in SCROBBLES_WITHOUT_CHARTS:
|
||||
return
|
||||
|
||||
if instance.media_type.lower() not in CHARTABLE_MEDIA_TYPES:
|
||||
return
|
||||
|
||||
_update_charts_for_timestamp(instance.user, instance.timestamp)
|
||||
@ -30,7 +33,10 @@ def update_charts_on_scrobble_delete(sender, instance, **kwargs):
|
||||
if instance.timestamp is None:
|
||||
return
|
||||
|
||||
if instance.media_type.lower() not in MEDIA_TYPES:
|
||||
if instance.media_type.lower() in SCROBBLES_WITHOUT_CHARTS:
|
||||
return
|
||||
|
||||
if instance.media_type.lower() not in CHARTABLE_MEDIA_TYPES:
|
||||
return
|
||||
|
||||
_update_charts_for_timestamp(instance.user, instance.timestamp)
|
||||
|
||||
@ -16,7 +16,7 @@ from django.utils import timezone
|
||||
logger = logging.getLogger(__name__)
|
||||
User = get_user_model()
|
||||
|
||||
MEDIA_TYPES = [
|
||||
CHARTABLE_MEDIA_TYPES = [
|
||||
"artist",
|
||||
"album",
|
||||
"track",
|
||||
@ -29,6 +29,10 @@ MEDIA_TYPES = [
|
||||
"book",
|
||||
]
|
||||
|
||||
SCROBBLES_WITHOUT_CHARTS = [
|
||||
"geolocation",
|
||||
]
|
||||
|
||||
|
||||
@shared_task
|
||||
def check_twitch_channels_for_vods():
|
||||
@ -167,7 +171,7 @@ def rebuild_weekly_charts():
|
||||
now = timezone.now()
|
||||
year, week, _ = now.isocalendar()
|
||||
for user in User.objects.all():
|
||||
build_weekly_charts(user, year, week, MEDIA_TYPES)
|
||||
build_weekly_charts(user, year, week, CHARTABLE_MEDIA_TYPES)
|
||||
logger.info(f"Rebuilt weekly charts for week {week}, {year}")
|
||||
|
||||
|
||||
@ -182,7 +186,7 @@ def rebuild_monthly_charts():
|
||||
else:
|
||||
month -= 1
|
||||
for user in User.objects.all():
|
||||
build_monthly_charts(user, year, month, MEDIA_TYPES)
|
||||
build_monthly_charts(user, year, month, CHARTABLE_MEDIA_TYPES)
|
||||
logger.info(f"Rebuilt monthly charts for {month}/{year}")
|
||||
|
||||
|
||||
@ -192,7 +196,7 @@ def rebuild_yearly_charts():
|
||||
now = timezone.now()
|
||||
year = now.year - 1
|
||||
for user in User.objects.all():
|
||||
build_yearly_charts(user, year, MEDIA_TYPES)
|
||||
build_yearly_charts(user, year, CHARTABLE_MEDIA_TYPES)
|
||||
logger.info(f"Rebuilt yearly charts for {year}")
|
||||
|
||||
|
||||
@ -205,10 +209,10 @@ def update_charts_for_timestamp(user_id, year, month, day, week):
|
||||
return
|
||||
|
||||
try:
|
||||
build_daily_charts(user, year, month, day, MEDIA_TYPES)
|
||||
build_weekly_charts(user, year, week, MEDIA_TYPES)
|
||||
build_monthly_charts(user, year, month, MEDIA_TYPES)
|
||||
build_yearly_charts(user, year, MEDIA_TYPES)
|
||||
build_daily_charts(user, year, month, day, CHARTABLE_MEDIA_TYPES)
|
||||
build_weekly_charts(user, year, week, CHARTABLE_MEDIA_TYPES)
|
||||
build_monthly_charts(user, year, month, CHARTABLE_MEDIA_TYPES)
|
||||
build_yearly_charts(user, year, CHARTABLE_MEDIA_TYPES)
|
||||
date_str = f"{year}-{month:02d}-{day:02d}"
|
||||
logger.info(f"[charts] Updated charts for {user} on {date_str}")
|
||||
except Exception as e:
|
||||
|
||||
Reference in New Issue
Block a user