Skip to content

Commit

Permalink
Update mysqlclient, add collation to fix migration error, limit sugge…
Browse files Browse the repository at this point in the history
…sted artcles query so that it doesn't take crazy long
  • Loading branch information
SamuelmdLow committed Nov 14, 2024
1 parent b4ebc32 commit a25b8a2
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 11 deletions.
18 changes: 9 additions & 9 deletions article/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1197,27 +1197,27 @@ def get_authors_split_out_visual_bylines(self) -> str:
return writers + visuals
authors_split_out_visual_bylines = property(fget=get_authors_split_out_visual_bylines)

def get_category_articles(self, order='-first_published_at') -> QuerySet:
def get_category_articles(self, order='-first_published_at', max=10) -> QuerySet:
"""
Returns a list of articles within the Article's category
"""
category_articles = ArticlePage.objects.live().filter(category=self.category).not_page(self).order_by(order)
category_articles = ArticlePage.objects.live().filter(category=self.category).not_page(self).order_by(order)[:max]

return category_articles

def get_section_articles(self, order='-first_published_at') -> QuerySet:
def get_section_articles(self, order='-first_published_at', max=10) -> QuerySet:
"""
Returns a list of articles within the Article's section
"""

section_articles = ArticlePage.objects.live().child_of(self.get_parent()).not_page(self).order_by(order)
section_articles = ArticlePage.objects.live().child_of(self.get_parent()).not_page(self).order_by(order)[:max]

return section_articles
def get_articles_by_tag(self, order='-first_published_at') -> QuerySet:
def get_articles_by_tag(self, order='-first_published_at', max=10) -> QuerySet:
"""
Returns a list of articles with the same tags as the current article
"""
articles_by_tag = ArticlePage.objects.live().filter(tags__slug=self.primary_tag_slug).not_page(self).order_by(order)
articles_by_tag = ArticlePage.objects.live().filter(tags__slug=self.primary_tag_slug).not_page(self).order_by(order)[:max]
return articles_by_tag

def get_suggested(self, number_suggested=3):
Expand All @@ -1227,7 +1227,7 @@ def get_suggested(self, number_suggested=3):
from taggit.models import Tag
suggested = {}
if self.filter_by_tags:
articles_by_tag = self.get_articles_by_tag()
articles_by_tag = self.get_articles_by_tag(max=number_suggested)
if len(articles_by_tag) > 0:
tag = Tag.objects.get(slug=self.primary_tag_slug)
suggested = {}
Expand All @@ -1236,15 +1236,15 @@ def get_suggested(self, number_suggested=3):
suggested['link'] = "/tag/" + tag.slug
if not suggested:
if self.category != None:
category_articles = self.get_category_articles()
category_articles = self.get_category_articles(max=number_suggested)
if len(category_articles) > 0:
suggested = {}
suggested['title'] = self.category.title
suggested['articles'] = category_articles[:number_suggested]
suggested['link'] = self.category.section_page.url + "category/" + self.category.slug

if not suggested:
section_articles = self.get_section_articles()
section_articles = self.get_section_articles(max=number_suggested)
if len(section_articles) > 0:
suggested = {}
suggested['title'] = self.get_parent().title
Expand Down
1 change: 1 addition & 0 deletions config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@
'PORT': '3306',
"OPTIONS": {
"charset": "utf8mb4",
"collation": "utf8mb4_0900_ai_ci",
},
},
}
Expand Down
2 changes: 1 addition & 1 deletion requirements-prd.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ django-storages[google]==1.14.2
django-canonical-domain==0.3.0
django-taggit==4.0.0
pymemcache==4.0.0
mysqlclient==2.0.1
mysqlclient==2.2.6
django-phonenumber-field==2.0.0
phonenumbers==8.12.9
beautifulsoup4==4.11.2
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ django-storages[google]==1.14.2
django-canonical-domain==0.3.0
django-taggit==4.0.0
pymemcache==4.0.0
mysqlclient==2.0.1
mysqlclient==2.2.6
beautifulsoup4==4.11.2
feedparser==6.0.10
pyyaml==6.0.1
Expand Down

0 comments on commit a25b8a2

Please sign in to comment.