mirror of
https://github.com/Freika/dawarich.git
synced 2026-01-11 09:41:40 -05:00
Add cache to points limit exceeded check
This commit is contained in:
parent
2206622726
commit
7afc399724
4 changed files with 20 additions and 4 deletions
|
|
@ -1 +1 @@
|
||||||
0.30.0
|
0.30.1
|
||||||
|
|
|
||||||
|
|
@ -4,10 +4,16 @@ All notable changes to this project will be documented in this file.
|
||||||
The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
||||||
and this project adheres to [Semantic Versioning](http://semver.org/).
|
and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||||
|
|
||||||
|
# [0.30.1] - 2025-07-21
|
||||||
|
|
||||||
|
## Fixed
|
||||||
|
|
||||||
|
- Points limit exceeded check is now cached.
|
||||||
|
|
||||||
|
|
||||||
# [0.30.0] - 2025-07-21
|
# [0.30.0] - 2025-07-21
|
||||||
|
|
||||||
⚠️ If you were using RC, please run the following commands in the console, otherwise read on. ⚠️
|
⚠️ If you were using 0.29.2 RC, please run the following commands in the console, otherwise read on. ⚠️
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
# This will delete all tracks 👇
|
# This will delete all tracks 👇
|
||||||
|
|
|
||||||
|
|
@ -7,13 +7,18 @@ class PointsLimitExceeded
|
||||||
|
|
||||||
def call
|
def call
|
||||||
return false if DawarichSettings.self_hosted?
|
return false if DawarichSettings.self_hosted?
|
||||||
return true if @user.tracked_points.count >= points_limit
|
|
||||||
|
|
||||||
false
|
Rails.cache.fetch(cache_key, expires_in: 1.day) do
|
||||||
|
@user.tracked_points.count >= points_limit
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def cache_key
|
||||||
|
"points_limit_exceeded/#{@user.id}"
|
||||||
|
end
|
||||||
|
|
||||||
def points_limit
|
def points_limit
|
||||||
DawarichSettings::BASIC_PAID_PLAN_LIMIT
|
DawarichSettings::BASIC_PAID_PLAN_LIMIT
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,11 @@ RSpec.describe PointsLimitExceeded do
|
||||||
end
|
end
|
||||||
|
|
||||||
it { is_expected.to be true }
|
it { is_expected.to be true }
|
||||||
|
|
||||||
|
it 'caches the result' do
|
||||||
|
expect(user.tracked_points).to receive(:count).once
|
||||||
|
2.times { described_class.new(user).call }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when user points count exceeds the limit' do
|
context 'when user points count exceeds the limit' do
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue