From 191bfd07e91f3aad94feec730b646dd3d9e82e8e Mon Sep 17 00:00:00 2001 From: retroinspect Date: Thu, 6 Apr 2023 13:45:53 +0000 Subject: [PATCH 1/2] Fix no src img exception --- apps/core/management/scripts/portal_crawler.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/apps/core/management/scripts/portal_crawler.py b/apps/core/management/scripts/portal_crawler.py index e71b68b2..c2913351 100644 --- a/apps/core/management/scripts/portal_crawler.py +++ b/apps/core/management/scripts/portal_crawler.py @@ -101,6 +101,9 @@ def _get_new_url_and_save_to_s3(url, session): hash = enc.hexdigest()[:20] filename = f'files/portal_image_{hash}.{url.split("_")[-1]}' + if url.startswith("/board"): + url = str(BASE_URL) + url + r = session.get(url, stream=True, cookies=COOKIES) if r.status_code == 200: s3 = boto3.client("s3") @@ -112,6 +115,8 @@ def _save_portal_image(html, session): soup = bs(html, "lxml") for child in soup.find_all("img", {}): old_url = child.attrs.get("src") + if old_url is None: + continue new_url = _get_new_url_and_save_to_s3(old_url, session) child["src"] = new_url From 326d0c3e4e660f1a762cf9eda7213026217a8a6e Mon Sep 17 00:00:00 2001 From: retroinspect Date: Tue, 23 Jan 2024 13:46:16 +0000 Subject: [PATCH 2/2] fix(article): remove index including created_at to prevent performance issue --- .../migrations/0057_alter_article_name_type_and_more.py | 7 ------- apps/core/models/article.py | 7 ------- 2 files changed, 14 deletions(-) diff --git a/apps/core/migrations/0057_alter_article_name_type_and_more.py b/apps/core/migrations/0057_alter_article_name_type_and_more.py index d23bfcbf..d5e0c5b8 100644 --- a/apps/core/migrations/0057_alter_article_name_type_and_more.py +++ b/apps/core/migrations/0057_alter_article_name_type_and_more.py @@ -20,11 +20,4 @@ class Migration(migrations.Migration): verbose_name="익명 혹은 실명 여부", ), ), - migrations.AddIndex( - model_name="article", - index=models.Index( - fields=["created_at", "parent_board_id"], - name="created_at_parent_board_id_idx", - ), - ), ] diff --git a/apps/core/models/article.py b/apps/core/models/article.py index 4525bc4e..d2b9a2a0 100644 --- a/apps/core/models/article.py +++ b/apps/core/models/article.py @@ -158,13 +158,6 @@ class Meta(MetaDataModel.Meta): verbose_name = "게시물" verbose_name_plural = "게시물 목록" - indexes = [ - models.Index( - fields=["created_at", "parent_board_id"], - name="created_at_parent_board_id_idx", - ) - ] - def __str__(self): return self.title