today_ai_weather/app/controllers/home_controller.rb
songtianlun f5009a6d2e feat: add lazy loading for images
- Implement lazy loading for images in various views
- Update image preview method to use medium size
- Cache latest arts to improve performance

These changes enhance the user experience by reducing initial
load times and improving performance. Lazy loading ensures that
images are only loaded when they are in the viewport, which
saves bandwidth and speeds up page rendering.
2025-04-27 17:19:52 +08:00

17 lines
746 B
Ruby

class HomeController < ApplicationController
def index
@latest_arts = Rails.cache.fetch("latest_arts", expires_in: 1.hour) do
WeatherArt.includes(:image_attachment, city: :country).latest(6)
end
# @popular_arts = WeatherArt.includes(:image_attachment, city: :country).by_popularity(3)
# @latest_arts = WeatherArt.includes(:image_attachment, city: :country).latest(6)
# @random_arts = WeatherArt.includes(:city, :image_attachment).random(3)
# @featured_arts = WeatherArt.includes(:city, :image_attachment).order(created_at: :desc).limit(5)
set_meta_tags(
title: t("meta.home.index.title"),
description: t("meta.home.index.description"),
keywords: t("meta.home.index.keywords")
)
end
end