Skip to content

Commit

Permalink
Set expire time for cache used in debounce (#82)
Browse files Browse the repository at this point in the history
* Set expire time for cache used in debounce

* bump version in Gemfile.lock

* fix vulnerabilities

* adjust actions: drop 2.7 ruby support, add 3.3

* fix changelog, drop ruby 2.7 support, fix version number

* fix rubocop issues

---------

Co-authored-by: aleksandr.kol <[email protected]>
  • Loading branch information
firstsano and aleksandr.kol authored Mar 25, 2024
1 parent c6b46b9 commit d3c0937
Show file tree
Hide file tree
Showing 10 changed files with 91 additions and 67 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
strategy:
fail-fast: false
matrix:
ruby: ["2.7", "3.0", "3.1", "3.2"]
ruby: ["3.0", "3.1", "3.2", "3.3"]

name: ${{ matrix.ruby }}

Expand Down
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ inherit_gem:
rubocop-config-umbrellio: lib/rubocop.yml

AllCops:
TargetRubyVersion: 2.7
TargetRubyVersion: 3.0
Include:
- bin/*
- lib/**/*.rb
Expand Down
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
# Changelog
All notable changes to this project will be documented in this file.

## [6.5.0] - 2024-03-19
### Added
- Add ruby 3.3 to ci workflow

### Changed
- Add expiration time for cache used in debouncing sync
- Update dependencies
- Fix rubocop issue
- Drop ruby 2.7 support

### Removed
- Remove ruby 2.7 from ci workflow

## [6.4.2] - 2023-11-14
### Added
- Required fields allow accepting empty collections.
Expand Down
114 changes: 57 additions & 57 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
table_sync (6.4.2)
table_sync (6.5.0)
memery
rabbit_messaging (~> 0.13)
rails
Expand All @@ -10,67 +10,67 @@ PATH
GEM
remote: https://rubygems.org/
specs:
actioncable (7.0.7.1)
actionpack (= 7.0.7.1)
activesupport (= 7.0.7.1)
actioncable (7.0.8.1)
actionpack (= 7.0.8.1)
activesupport (= 7.0.8.1)
nio4r (~> 2.0)
websocket-driver (>= 0.6.1)
actionmailbox (7.0.7.1)
actionpack (= 7.0.7.1)
activejob (= 7.0.7.1)
activerecord (= 7.0.7.1)
activestorage (= 7.0.7.1)
activesupport (= 7.0.7.1)
actionmailbox (7.0.8.1)
actionpack (= 7.0.8.1)
activejob (= 7.0.8.1)
activerecord (= 7.0.8.1)
activestorage (= 7.0.8.1)
activesupport (= 7.0.8.1)
mail (>= 2.7.1)
net-imap
net-pop
net-smtp
actionmailer (7.0.7.1)
actionpack (= 7.0.7.1)
actionview (= 7.0.7.1)
activejob (= 7.0.7.1)
activesupport (= 7.0.7.1)
actionmailer (7.0.8.1)
actionpack (= 7.0.8.1)
actionview (= 7.0.8.1)
activejob (= 7.0.8.1)
activesupport (= 7.0.8.1)
mail (~> 2.5, >= 2.5.4)
net-imap
net-pop
net-smtp
rails-dom-testing (~> 2.0)
actionpack (7.0.7.1)
actionview (= 7.0.7.1)
activesupport (= 7.0.7.1)
actionpack (7.0.8.1)
actionview (= 7.0.8.1)
activesupport (= 7.0.8.1)
rack (~> 2.0, >= 2.2.4)
rack-test (>= 0.6.3)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.2.0)
actiontext (7.0.7.1)
actionpack (= 7.0.7.1)
activerecord (= 7.0.7.1)
activestorage (= 7.0.7.1)
activesupport (= 7.0.7.1)
actiontext (7.0.8.1)
actionpack (= 7.0.8.1)
activerecord (= 7.0.8.1)
activestorage (= 7.0.8.1)
activesupport (= 7.0.8.1)
globalid (>= 0.6.0)
nokogiri (>= 1.8.5)
actionview (7.0.7.1)
activesupport (= 7.0.7.1)
actionview (7.0.8.1)
activesupport (= 7.0.8.1)
builder (~> 3.1)
erubi (~> 1.4)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.1, >= 1.2.0)
activejob (7.0.7.1)
activesupport (= 7.0.7.1)
activejob (7.0.8.1)
activesupport (= 7.0.8.1)
globalid (>= 0.3.6)
activemodel (7.0.7.1)
activesupport (= 7.0.7.1)
activerecord (7.0.7.1)
activemodel (= 7.0.7.1)
activesupport (= 7.0.7.1)
activestorage (7.0.7.1)
actionpack (= 7.0.7.1)
activejob (= 7.0.7.1)
activerecord (= 7.0.7.1)
activesupport (= 7.0.7.1)
activemodel (7.0.8.1)
activesupport (= 7.0.8.1)
activerecord (7.0.8.1)
activemodel (= 7.0.8.1)
activesupport (= 7.0.8.1)
activestorage (7.0.8.1)
actionpack (= 7.0.8.1)
activejob (= 7.0.8.1)
activerecord (= 7.0.8.1)
activesupport (= 7.0.8.1)
marcel (~> 1.0)
mini_mime (>= 1.1.0)
activesupport (7.0.7.1)
activesupport (7.0.8.1)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 1.6, < 2)
minitest (>= 5.1)
Expand Down Expand Up @@ -106,7 +106,7 @@ GEM
net-imap
net-pop
net-smtp
marcel (1.0.2)
marcel (1.0.4)
memery (1.5.0)
ruby2_keywords (~> 0.0.2)
method_source (1.0.0)
Expand All @@ -123,7 +123,7 @@ GEM
net-smtp (0.3.3)
net-protocol
nio4r (2.5.9)
nokogiri (1.15.4)
nokogiri (1.16.3)
mini_portile2 (~> 2.8.2)
racc (~> 1.4)
parallel (1.23.0)
Expand All @@ -141,33 +141,33 @@ GEM
sneakers (~> 2.0)
tainbox
racc (1.7.1)
rack (2.2.8)
rack (2.2.8.1)
rack-test (2.1.0)
rack (>= 1.3)
rails (7.0.7.1)
actioncable (= 7.0.7.1)
actionmailbox (= 7.0.7.1)
actionmailer (= 7.0.7.1)
actionpack (= 7.0.7.1)
actiontext (= 7.0.7.1)
actionview (= 7.0.7.1)
activejob (= 7.0.7.1)
activemodel (= 7.0.7.1)
activerecord (= 7.0.7.1)
activestorage (= 7.0.7.1)
activesupport (= 7.0.7.1)
rails (7.0.8.1)
actioncable (= 7.0.8.1)
actionmailbox (= 7.0.8.1)
actionmailer (= 7.0.8.1)
actionpack (= 7.0.8.1)
actiontext (= 7.0.8.1)
actionview (= 7.0.8.1)
activejob (= 7.0.8.1)
activemodel (= 7.0.8.1)
activerecord (= 7.0.8.1)
activestorage (= 7.0.8.1)
activesupport (= 7.0.8.1)
bundler (>= 1.15.0)
railties (= 7.0.7.1)
railties (= 7.0.8.1)
rails-dom-testing (2.2.0)
activesupport (>= 5.0.0)
minitest
nokogiri (>= 1.6)
rails-html-sanitizer (1.6.0)
loofah (~> 2.21)
nokogiri (~> 1.14)
railties (7.0.7.1)
actionpack (= 7.0.7.1)
activesupport (= 7.0.7.1)
railties (7.0.8.1)
actionpack (= 7.0.8.1)
activesupport (= 7.0.8.1)
method_source
rake (>= 12.2)
thor (~> 1.0)
Expand Down
6 changes: 5 additions & 1 deletion lib/table_sync/publishing/helpers/debounce.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,11 @@ def debounced_sync_time
end

def cache_next_sync_time
Rails.cache.write(cache_key, next_sync_time)
Rails.cache.write(
cache_key,
next_sync_time,
expires_at: next_sync_time + debounce_time.seconds,
)
end

def cache_key
Expand Down
2 changes: 1 addition & 1 deletion lib/table_sync/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module TableSync
VERSION = "6.4.2"
VERSION = "6.5.0"
end
13 changes: 10 additions & 3 deletions spec/publishing/helpers/debounce_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,17 @@ def set_cached_sync_time(time)
let(:expected_time) { current_time }
let(:cached_time) { current_time - 30.seconds }

before { set_cached_sync_time(cached_time) }
context "cache existed" do
before { set_cached_sync_time(cached_time) }

include_examples "skip? returns", false
include_examples "returns correct next_sync_time"
include_examples "skip? returns", false
include_examples "returns correct next_sync_time"
end

context "cache expired" do
include_examples "skip? returns", false
include_examples "returns correct next_sync_time"
end
end

context "case 2.2: debounce time not passed yet" do
Expand Down
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
require "rabbit/test_helpers" # NOTE: from rabbit_messaging
require "table_sync"

Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].sort.each { |file| require file }
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |file| require file }

TableSync::TestEnv.setup!

Expand Down
2 changes: 1 addition & 1 deletion spec/support/cache_utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def read(key)
store[key]
end

def write(key, value)
def write(key, value, _options = nil)
store[key] = value
end

Expand Down
2 changes: 1 addition & 1 deletion table_sync.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require "table_sync/version"

Gem::Specification.new do |spec|
spec.required_ruby_version = ">= 2.7.0"
spec.required_ruby_version = ">= 3.0.0"

spec.name = "table_sync"
spec.version = TableSync::VERSION
Expand Down

0 comments on commit d3c0937

Please sign in to comment.