mirror of
https://github.com/Freika/dawarich.git
synced 2026-01-10 01:01:39 -05:00
* Implement some performance improvements and caching for various features. * Fix failing tests * Implement routes behaviour in map v2 to match map v1 * Fix route highlighting * Add fallbacks when retrieving full route features to handle cases where source data access methods vary. * Fix some e2e tests
41 lines
1 KiB
Ruby
41 lines
1 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
class Cache::PreheatingJob < ApplicationJob
|
|
queue_as :cache
|
|
|
|
def perform
|
|
User.find_each do |user|
|
|
Rails.cache.write(
|
|
"dawarich/user_#{user.id}_years_tracked",
|
|
user.years_tracked,
|
|
expires_in: 1.day
|
|
)
|
|
|
|
Rails.cache.write(
|
|
"dawarich/user_#{user.id}_points_geocoded_stats",
|
|
StatsQuery.new(user).cached_points_geocoded_stats,
|
|
expires_in: 1.day
|
|
)
|
|
|
|
Rails.cache.write(
|
|
"dawarich/user_#{user.id}_countries_visited",
|
|
user.countries_visited_uncached,
|
|
expires_in: 1.day
|
|
)
|
|
|
|
Rails.cache.write(
|
|
"dawarich/user_#{user.id}_cities_visited",
|
|
user.cities_visited_uncached,
|
|
expires_in: 1.day
|
|
)
|
|
|
|
# Preheat total_distance cache
|
|
total_distance_meters = user.stats.sum(:distance)
|
|
Rails.cache.write(
|
|
"dawarich/user_#{user.id}_total_distance",
|
|
Stat.convert_distance(total_distance_meters, user.safe_settings.distance_unit),
|
|
expires_in: 1.day
|
|
)
|
|
end
|
|
end
|
|
end
|