diff --git a/backend/config/management/commands/ta_startup.py b/backend/config/management/commands/ta_startup.py index 3dc55e83..e80af6b7 100644 --- a/backend/config/management/commands/ta_startup.py +++ b/backend/config/management/commands/ta_startup.py @@ -55,6 +55,7 @@ class Command(BaseCommand): self._init_app_config() self._mig_channel_tags() self._mig_video_channel_tags() + self._mig_fix_download_channel_indexed() def _make_folders(self): """make expected cache folders""" @@ -347,3 +348,37 @@ class Command(BaseCommand): self.stdout.write(response) sleep(60) raise CommandError(message) + + def _mig_fix_download_channel_indexed(self) -> None: + """migrate from v0.5.2 to 0.5.3, fix missing channel_indexed""" + self.stdout.write("[MIGRATION] fix incorrect video channel tags types") + path = "ta_download/_update_by_query" + data = { + "query": { + "bool": { + "must_not": [{"exists": {"field": "channel_indexed"}}] + } + }, + "script": { + "source": "ctx._source.channel_indexed = false", + "lang": "painless", + }, + } + response, status_code = ElasticWrap(path).post(data) + if status_code in [200, 201]: + updated = response.get("updated") + if updated: + self.stdout.write( + self.style.SUCCESS(f" ✓ fixed {updated} queued videos") + ) + else: + self.stdout.write( + self.style.SUCCESS(" no queued videos to fix") + ) + return + + message = " 🗙 failed to fix video channel tags" + self.stdout.write(self.style.ERROR(message)) + self.stdout.write(response) + sleep(60) + raise CommandError(message) diff --git a/backend/download/src/queue.py b/backend/download/src/queue.py index e4238c18..eae697d5 100644 --- a/backend/download/src/queue.py +++ b/backend/download/src/queue.py @@ -344,11 +344,8 @@ class PendingList(PendingIndex): "duration": get_duration_str(vid["duration"]), "published": published, "timestamp": int(datetime.now().timestamp()), - # Pulling enum value out so it is serializable "vid_type": vid_type.value, + "channel_indexed": vid["channel_id"] in self.all_channels, } - if self.all_channels: - youtube_details.update( - {"channel_indexed": vid["channel_id"] in self.all_channels} - ) + return youtube_details