refactor: optimize includes for weather arts

- Changed includes for WeatherArt to optimize query
- Removed redundant includes of country in WeatherArt
- Simplified region fetching by directly ordering

These modifications improve the efficiency of the queries
by reducing unnecessary joins and utilizing ActiveRecord’s
query capabilities more effectively. The code change does not
affect the overall functionality but improves maintainability.
This commit is contained in:
songtianlun 2025-02-14 10:01:24 +08:00
parent 18977a9d42
commit 95afdf1096
2 changed files with 2 additions and 2 deletions

View File

@ -3,7 +3,7 @@ class ArtsController < ApplicationController
@regions = Region.all
@current_region = Region.find(params[:region]) if params[:region].present?
@weather_arts = WeatherArt.includes(city: [ :country, { country: :region } ])
@weather_arts = WeatherArt.includes(city: [ :country ]).includes(:image_attachment)
if @current_region
@weather_arts = @weather_arts.joins(city: :country)

View File

@ -3,7 +3,7 @@ class CitiesController < ApplicationController
before_action :require_admin, only: [ :generate_weather_art ]
def index
@regions = Region.includes(:countries).order(:name)
@regions = Region.order(:name)
@cities = City.includes(:country, country: :region).order(:name)
if params[:query].present?