Fix articles endpoint performance

This commit is contained in:
Pranav
2025-01-11 23:08:37 -08:00
parent 74870bec41
commit 502b950f83
3 changed files with 10 additions and 11 deletions
@@ -7,6 +7,7 @@ class Public::Api::V1::Portals::ArticlesController < Public::Api::V1::Portals::B
def index
@articles = @portal.articles.published
@articles_count = @articles.count
search_articles
order_by_sort_param
@articles.page(list_params[:page]) if list_params[:page].present?
@@ -44,7 +45,7 @@ class Public::Api::V1::Portals::ArticlesController < Public::Api::V1::Portals::B
end
def list_params
params.permit(:query, :locale, :sort, :status)
params.permit(:query, :locale, :sort, :status, :page)
end
def permitted_params
@@ -11,7 +11,13 @@ json.slug article.slug
if article.portal.present?
json.portal do
json.partial! 'public/api/v1/models/hc/portal', formats: [:json], portal: article.portal
json.custom_domain article.portal.custom_domain
json.header_text article.portal.header_text
json.homepage_link article.portal.homepage_link
json.name article.portal.name
json.page_title article.portal.page_title
json.slug article.portal.slug
json.logo article.portal.file_base_data if article.portal.logo.present?
end
end
@@ -31,12 +37,4 @@ if article.author.present?
end
end
json.associated_articles do
if article.associated_articles.any?
json.array! article.associated_articles.each do |associated_article|
json.partial! 'public/api/v1/models/hc/associated_article', formats: [:json], article: associated_article
end
end
end
json.link "hc/#{article.portal.slug}/articles/#{article.slug}"
@@ -4,5 +4,5 @@ json.payload do
end
json.meta do
json.articles_count @articles.published.size
json.articles_count @articles_count
end