feat: improve weather art display and generation

- Display the latest weather art on the cities index page.
- Update the weather art preview image size to be big.
- Improve image display by using webp format.
- Adjust the daily and per-run generation limits.

These changes enhance the user experience by providing more
up-to-date and visually appealing content, while also controlling
the resource usage during image generation.
This commit is contained in:
songtianlun 2025-02-17 00:15:32 +08:00
parent fa1fc7c21a
commit f02587da57
5 changed files with 6 additions and 5 deletions

View File

@ -5,6 +5,7 @@ class CitiesController < ApplicationController
def index def index
@regions = Region.order(:name) @regions = Region.order(:name)
@cities = City.includes(:country, country: :region).order(:name) @cities = City.includes(:country, country: :region).order(:name)
@latest_arts = WeatherArt.includes(:city, :image_attachment).latest(1)
if params[:query].present? if params[:query].present?
@cities = @cities.search_by_name(params[:query]) @cities = @cities.search_by_name(params[:query])

View File

@ -120,7 +120,7 @@ class WeatherArt < ApplicationRecord
medium: [ 896, 512 ], medium: [ 896, 512 ],
small: [ 448, 256 ] small: [ 448, 256 ]
}.freeze }.freeze
def preview_image(size = :medium) def preview_image(size = :big)
return nil unless image.attached? return nil unless image.attached?
width, height = PREVIEW_DIMENSIONS[size] || PREVIEW_DIMENSIONS[:medium] width, height = PREVIEW_DIMENSIONS[size] || PREVIEW_DIMENSIONS[:medium]

View File

@ -1,7 +1,7 @@
<!-- app/views/cities/index.html.erb --> <!-- app/views/cities/index.html.erb -->
<div class="min-h-screen"> <div class="min-h-screen">
<!-- 页面标题和背景 --> <!-- 页面标题和背景 -->
<% featured_art = WeatherArt.includes(:city).joins(:image_attachment).order(created_at: :desc).first %> <% featured_art = @latest_arts.first %>
<div class="relative bg-base-100"> <div class="relative bg-base-100">
<!-- 背景图像和渐变 --> <!-- 背景图像和渐变 -->
<% if featured_art&.image&.attached? %> <% if featured_art&.image&.attached? %>

View File

@ -3,7 +3,7 @@
<section class="h-screen-90 relative overflow-hidden"> <section class="h-screen-90 relative overflow-hidden">
<% if @latest_arts.first&.image&.attached? %> <% if @latest_arts.first&.image&.attached? %>
<div class="absolute inset-0"> <div class="absolute inset-0">
<%= image_tag @latest_arts.first.preview_image(:large).processed, class: "w-full h-full object-cover" %> <%= image_tag @latest_arts.first.webp_image.processed, class: "w-full h-full object-cover" %>
<div class="absolute inset-0 bg-gradient-to-r from-base-100/90 to-base-100/50"></div> <div class="absolute inset-0 bg-gradient-to-r from-base-100/90 to-base-100/50"></div>
</div> </div>
<% end %> <% end %>

View File

@ -4,8 +4,8 @@ class BatchGenerateWeatherArtsWorker
GENERATION_INTERVAL = 36.hours GENERATION_INTERVAL = 36.hours
MAX_DURATION = 5.minutes MAX_DURATION = 5.minutes
SLEEP_DURATION = 10.seconds SLEEP_DURATION = 10.seconds
DAILY_GENERATION_LIMIT = 50 # 每日生成图片上限 DAILY_GENERATION_LIMIT = 60 # 每日生成图片上限
PER_RUN_GENERATION_LIMIT = 5 # 每次运行生成图片上限 PER_RUN_GENERATION_LIMIT = 3 # 每次运行生成图片上限
def perform(*args) def perform(*args)
start_time = Time.current start_time = Time.current