Consider alternative approach for sponsor logo storage
Current Approach
Currently sponsors use a hybrid approach for storing logos:
- External URL is stored in the
logo_urlfield - Fallback to local assets in
app/assets/images/sponsors/{slug}/logo.webp - If local asset doesn't exist, external URL is used
This approach may be inconsistent with the rest of the application, where external image URLs are never stored.
Current Approach Analysis
Sponsors (Possibly Inconsistent)
def logo_image_path
# First try local asset, then fallback to logo_url
if sponsor_image_for("logo.webp")
sponsor_image_or_default_for("logo.webp")
elsif logo_url.present?
logo_url # ← External URL
else
sponsor_image_or_default_for("logo.webp")
end
end
Events (App Standard)
def avatar_image_path
event_image_or_default_for("avatar.webp") # ← Local assets only
end
Proposed Alternative Approach
1. Remove external URL fields
- Remove
logo_urlandlogo_urlsfrom database - Migrate existing data by downloading images
- Still use
logo_urlfield from YAML files created by the scraper to download the images.
2. Use local assets only
- Structure:
app/assets/images/sponsors/{slug}/logo.webp - Keep fallback system to
sponsors/default/logo.webp - Standardize with the rest of the application
3. Maintain existing functionality
- Background color:
logo_background(white/black/transparent) - Border styling:
logo_border_class - Fallback system: Default image if none exists
Justification
- Consistency: Align with app standard where external URLs are never stored
- Performance: Load from local instead of external servers
- Reliability: No dependency on external sites that might go down
- Maintainability: Single approach for all images
Implementation Plan
- Create script to download existing logos
- Database migration to remove URL fields
- Update model to use local assets only
- Add a lib that downloads and stores images from scraped data of sponsors (stored in YAML files)
Future Enhancement
We can use the sponsor slugs to tag companies and potentially reach out to them to provide optimized assets themselves. While this won't always happen, it's worth trying as suggested by @brauliomartinezlm. This would ensure we have the highest quality, properly optimized logos directly from the source.
Acknowledgment
I want to say that I saw the PR #885 @marcoroth did, doing an effort on the current logo_url implementation.
I'm simply wondering if we might explore aligning this one aspect more closely with the established patterns used elsewhere in the application, but I fully acknowledge that the current implementation is likely the result of careful consideration and may have valid reasons for its design that I haven't fully grasped yet.
Not sure how applicable it would be here but as an alternative to #881 I think I will add a little ActiveStorage to store the PictureProfile
But for now I would prefer that we store only non critical assets as I plan to use the VPS file system (or a mounted drive)