Skip to content

Commit

Permalink
Web filter param not working in pagination (#584)
Browse files Browse the repository at this point in the history
* Update changelog

* Bump sidekiq-unique-jobs to 7.0.6

* Bump dependency for brpoplpush-redis_script

* Add gem to match html

* Fix building on push

* Preserve filter param in url

* Allow cursor, count and filter to be passed

* Mandatory rubocop commit

* Refreh gemspecs and test Sidekiq 6.2

* Disable pagination spec for sidekiq < 6

* Fix pagination as well as can be fixed

Redis SCAN is not super accurate but this should do the trick
  • Loading branch information
mhenrixon authored Mar 19, 2021
1 parent b0fa628 commit fd3d83e
Show file tree
Hide file tree
Showing 18 changed files with 147 additions and 44 deletions.
17 changes: 14 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@

- Any way to manually clear/reset the changelog history? [\#568](https://github.com/mhenrixon/sidekiq-unique-jobs/issues/568)
- Present the entire changelog in its own view [\#569](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/569) ([mhenrixon](https://github.com/mhenrixon))
- Give user full control over adding middleware [\#566](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/566) ([mhenrixon](https://github.com/mhenrixon))

**Fixed bugs:**

Expand Down Expand Up @@ -165,6 +166,10 @@
- Documentation incorrect for `delete\_by\_digest` [\#547](https://github.com/mhenrixon/sidekiq-unique-jobs/issues/547)
- Locked jobs after kill -9 with while\_executing lock [\#546](https://github.com/mhenrixon/sidekiq-unique-jobs/issues/546)

**Merged pull requests:**

- Support apartment [\#540](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/540) ([mhenrixon](https://github.com/mhenrixon))

## [v7.0.0.beta26](https://github.com/mhenrixon/sidekiq-unique-jobs/tree/v7.0.0.beta26) (2020-10-28)

[Full Changelog](https://github.com/mhenrixon/sidekiq-unique-jobs/compare/v6.0.25...v7.0.0.beta26)
Expand Down Expand Up @@ -311,6 +316,7 @@

- Deprecate configuration options with `default\_` [\#504](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/504) ([mhenrixon](https://github.com/mhenrixon))
- Fix access to both server and client conflict [\#503](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/503) ([mhenrixon](https://github.com/mhenrixon))
- Use thread-safe digest creation mechanism [\#484](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/484) ([mhenrixon](https://github.com/mhenrixon))

**Closed issues:**

Expand Down Expand Up @@ -372,6 +378,10 @@
- until\_expired is not setting TTL [\#468](https://github.com/mhenrixon/sidekiq-unique-jobs/issues/468)
- Fix bug where expiration wasn't set until unlock [\#481](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/481) ([mhenrixon](https://github.com/mhenrixon))

**Merged pull requests:**

- Allow v7 configuration to work [\#479](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/479) ([mhenrixon](https://github.com/mhenrixon))

## [v6.0.20](https://github.com/mhenrixon/sidekiq-unique-jobs/tree/v6.0.20) (2020-03-22)

[Full Changelog](https://github.com/mhenrixon/sidekiq-unique-jobs/compare/v7.0.0.beta11...v6.0.20)
Expand Down Expand Up @@ -552,6 +562,7 @@

- Redis is busy running script and script never terminates [\#441](https://github.com/mhenrixon/sidekiq-unique-jobs/issues/441)
- Make the ruby reaper plain ruby [\#443](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/443) ([mhenrixon](https://github.com/mhenrixon))
- Fix sidekiq develop [\#426](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/426) ([mhenrixon](https://github.com/mhenrixon))

**Closed issues:**

Expand Down Expand Up @@ -590,9 +601,9 @@
**Fixed bugs:**

- Allow Sidekiq::Context to be used for logging [\#429](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/429) ([mhenrixon](https://github.com/mhenrixon))
- Fix sidekiq develop [\#426](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/426) ([mhenrixon](https://github.com/mhenrixon))
- Reap as many orphans as advertised [\#403](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/403) ([mhenrixon](https://github.com/mhenrixon))
- Reaper should remove :INFO keys [\#399](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/399) ([mhenrixon](https://github.com/mhenrixon))
- Convert v5 locks when needed [\#375](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/375) ([mhenrixon](https://github.com/mhenrixon))

**Merged pull requests:**

Expand Down Expand Up @@ -1409,7 +1420,6 @@
- Do not unlock on sidekiq shutdown [\#87](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/87) ([deltaroe](https://github.com/deltaroe))
- Remove no-op code, protect global space from test code [\#86](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/86) ([stevenjonescgm](https://github.com/stevenjonescgm))
- Remove unique lock when executing and clearing jobs in sidekiq fake mode [\#83](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/83) ([crberube](https://github.com/crberube))
- Fix tests. Tests with latest sidekiq versions and ruby versions [\#82](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/82) ([simonoff](https://github.com/simonoff))
- Duplicate Payload logging configuration [\#81](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/81) ([jprincipe](https://github.com/jprincipe))
- output log if not unique [\#79](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/79) ([sonots](https://github.com/sonots))
- Checking Sidekiq::Testing.inline? on testing strategy and connector [\#75](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/75) ([Draiken](https://github.com/Draiken))
Expand All @@ -1425,6 +1435,7 @@

**Merged pull requests:**

- Fix tests. Tests with latest sidekiq versions and ruby versions [\#82](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/82) ([simonoff](https://github.com/simonoff))
- Use ConnectionPool blocks to ensure exclusive connection. Closes \#66. [\#67](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/67) ([adstage-david](https://github.com/adstage-david))

## [v3.0.10](https://github.com/mhenrixon/sidekiq-unique-jobs/tree/v3.0.10) (2014-11-19)
Expand Down Expand Up @@ -1506,6 +1517,7 @@
- Clarify README about unique expiration [\#36](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/36) ([spacemunkay](https://github.com/spacemunkay))
- Add option to make jobs unique on all queues [\#32](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/32) ([robinmessage](https://github.com/robinmessage))
- Fix homepage in gemspec [\#29](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/29) ([tmaier](https://github.com/tmaier))
- Compatibility with Sidekiq 2.12.1 Scheduled Jobs [\#16](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/16) ([lsimoneau](https://github.com/lsimoneau))

## [v2.7.0](https://github.com/mhenrixon/sidekiq-unique-jobs/tree/v2.7.0) (2013-11-24)

Expand All @@ -1524,7 +1536,6 @@
- Make unlock/yield order configurable. [\#21](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/21) ([endofunky](https://github.com/endofunky))
- Rely on Sidekiq's String\#constantize extension instead of rolling our own [\#19](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/19) ([disbelief](https://github.com/disbelief))
- Attempt to constantize String `worker\_class` arguments passed to client middleware [\#17](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/17) ([disbelief](https://github.com/disbelief))
- Compatibility with Sidekiq 2.12.1 Scheduled Jobs [\#16](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/16) ([lsimoneau](https://github.com/lsimoneau))
- Allow worker to specify which arguments to include in uniquing hash [\#12](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/12) ([sax](https://github.com/sax))
- Add support for unique when using Sidekiq's delay function [\#11](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/11) ([eduardosasso](https://github.com/eduardosasso))
- Adding the unique prefix option [\#8](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/8) ([KensoDev](https://github.com/KensoDev))
Expand Down
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ gem "github-markup"
gem "rack-test"
gem "rake"
gem "rspec"
gem "rspec-html-matchers"
gem "rspec-its"
gem "sinatra"
gem "timecop"
Expand Down
1 change: 1 addition & 0 deletions gemfiles/sidekiq_5.0.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ gem "github-markup"
gem "rack-test"
gem "rake"
gem "rspec"
gem "rspec-html-matchers"
gem "rspec-its"
gem "sinatra"
gem "timecop"
Expand Down
1 change: 1 addition & 0 deletions gemfiles/sidekiq_5.1.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ gem "github-markup"
gem "rack-test"
gem "rake"
gem "rspec"
gem "rspec-html-matchers"
gem "rspec-its"
gem "sinatra"
gem "timecop"
Expand Down
1 change: 1 addition & 0 deletions gemfiles/sidekiq_5.2.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ gem "github-markup"
gem "rack-test"
gem "rake"
gem "rspec"
gem "rspec-html-matchers"
gem "rspec-its"
gem "sinatra"
gem "timecop"
Expand Down
1 change: 1 addition & 0 deletions gemfiles/sidekiq_6.0.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ gem "github-markup"
gem "rack-test"
gem "rake"
gem "rspec"
gem "rspec-html-matchers"
gem "rspec-its"
gem "sinatra"
gem "timecop"
Expand Down
1 change: 1 addition & 0 deletions gemfiles/sidekiq_6.1.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ gem "github-markup"
gem "rack-test"
gem "rake"
gem "rspec"
gem "rspec-html-matchers"
gem "rspec-its"
gem "sinatra"
gem "timecop"
Expand Down
37 changes: 37 additions & 0 deletions gemfiles/sidekiq_6.2.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "appraisal"
gem "bundler"
gem "gem-release"
gem "github-markup"
gem "rack-test"
gem "rake"
gem "rspec"
gem "rspec-its"
gem "sinatra"
gem "timecop"
gem "yard"
gem "sidekiq", "~> 6.2.0"

platforms :mri do
gem "concurrent-ruby-ext"
gem "fasterer"
gem "github_changelog_generator"
gem "guard"
gem "guard-bundler"
gem "guard-reek"
gem "guard-rspec"
gem "guard-rubocop"
gem "hiredis"
gem "redcarpet", "~> 3.4"
gem "reek", ">= 5.3"
gem "rspec-benchmark"
gem "rubocop-mhenrixon"
gem "ruby-prof", require: false
gem "simplecov-sublime", "0.21.0", require: false
gem "travis"
end

gemspec path: "../"
1 change: 1 addition & 0 deletions gemfiles/sidekiq_develop.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ gem "github-markup"
gem "rack-test"
gem "rake"
gem "rspec"
gem "rspec-html-matchers"
gem "rspec-its"
gem "sinatra"
gem "timecop"
Expand Down
4 changes: 2 additions & 2 deletions lib/sidekiq_unique_jobs/changelog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ def page(cursor: 0, pattern: "*", page_size: 100)
end

[
total_size,
result[0], # next_cursor
total_size.to_i,
result[0].to_i, # next_cursor
result[1].map { |entry| load_json(entry[0]) }, # entries
]
end
Expand Down
4 changes: 2 additions & 2 deletions lib/sidekiq_unique_jobs/digests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ def page(cursor: 0, pattern: SCAN_PATTERN, page_size: 100)
end

[
total_size,
digests[0], # next_cursor
total_size.to_i,
digests[0].to_i, # next_cursor
digests[1].map { |digest, score| Lock.new(digest, time: score) }, # entries
]
end
Expand Down
15 changes: 11 additions & 4 deletions lib/sidekiq_unique_jobs/web.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@ def self.registered(app) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
@count = (params[:count] || 100).to_i
@current_cursor = params[:cursor]
@prev_cursor = params[:prev_cursor]
@pagination = { pattern: @filter, cursor: @current_cursor, page_size: @count }
@total_size, @next_cursor, @changelogs = changelog.page(**@pagination)
@total_size, @next_cursor, @changelogs = changelog.page(
cursor: @current_cursor,
pattern: @filter,
page_size: @count,
)

erb(unique_template(:changelogs))
end
Expand All @@ -36,8 +39,12 @@ def self.registered(app) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
@count = (params[:count] || 100).to_i
@current_cursor = params[:cursor]
@prev_cursor = params[:prev_cursor]
@pagination = { pattern: @filter, cursor: @current_cursor, page_size: @count }
@total_size, @next_cursor, @locks = digests.page(**@pagination)

@total_size, @next_cursor, @locks = digests.page(
cursor: @current_cursor,
pattern: @filter,
page_size: @count,
)

erb(unique_template(:locks))
end
Expand Down
10 changes: 5 additions & 5 deletions lib/sidekiq_unique_jobs/web/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ module Helpers
VIEW_PATH = File.expand_path("../web/views", __dir__).freeze
#
# @return [Array<String>] safe params
SAFE_CPARAMS = %w[cursor prev_cursor].freeze
SAFE_CPARAMS = %w[
filter count cursor prev_cursor poll direction
].freeze

extend self

Expand Down Expand Up @@ -67,10 +69,8 @@ def changelog
# @return [String] a url safe parameter string
#
def cparams(options)
# stringify
options.transform_keys(&:to_s)

params.merge(options).map do |key, value|
stringified_options = options.transform_keys(&:to_s)
params.merge(stringified_options).map do |key, value|
next unless SAFE_CPARAMS.include?(key)

"#{key}=#{CGI.escape(value.to_s)}"
Expand Down
8 changes: 4 additions & 4 deletions lib/sidekiq_unique_jobs/web/views/_paging.erb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<ul class="pagination pull-right flip">
<% if @prev_cursor %>
<li>
<a href="<%= url %>?<%= cparams(cursor: @prev_cursor, prev_cursor: @next_cursor) %>">Previous <%= @count %></a>
</li>
<li>
<a href="<%= url %>?<%= cparams(filter: @filter, cursor: @prev_cursor, prev_cursor: @next_cursor) %>">Previous <%= @count %></a>
</li>
<% end %>
<li>
<a href="<%= url %>?<%= cparams(cursor: @next_cursor, prev_cursor: @current_cursor) %>">Next <%= @count %></a>
<a href="<%= url %>?<%= cparams(filter: @filter, cursor: @next_cursor, prev_cursor: @current_cursor) %>">Next <%= @count %></a>
</li>
</ul>
2 changes: 1 addition & 1 deletion lib/sidekiq_unique_jobs/web/views/changelogs.erb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
</thead>
<tbody>
<% @changelogs.each do |changelog| %>
<tr>
<tr class="changelog-row">
<td><%= safe_relative_time(changelog["time"]) %></td>
<td><%= changelog["digest"] %></td>
<td><%= changelog["script"] %></td>
Expand Down
32 changes: 17 additions & 15 deletions lib/sidekiq_unique_jobs/web/views/locks.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<%= t('Filter') %>
</button>
</form>
<% if @locks.any? && @total_size > @count.to_i %>
<% if @locks.any? && @total_size > @count %>
<div class="col-sm-4">
<%= erb unique_template(:_paging), locals: { url: "#{root_path}locks" } %>
</div>
Expand All @@ -30,20 +30,22 @@
</tr>
</thead>
<% @locks.each do |lock| %>
<tr>
<td>
<form action="<%= root_path %>locks/<%= lock.key %>/delete" method="get">
<%= csrf_tag %>
<input name="lock" value="<%= h lock.key %>" type="hidden" />
<input class="btn btn-danger btn-xs" type="submit" name="delete" value="<%= t('Delete') %>" data-confirm="<%= t('AreYouSure') %>" />
</form>
</td>
<td><a href="<%= root_path %>locks/<%= lock.key %>"><%= lock.key %></a></td>
<td><%= lock.info["lock"] %></th>
<td><%= lock.locked.count %></td>
<td><%= safe_relative_time(lock.created_at) %></td>
</tr>
<% end %>
<tbody>
<tr class="lock-row">
<td>
<form action="<%= root_path %>locks/<%= lock.key %>/delete" method="get">
<%= csrf_tag %>
<input name="lock" value="<%= h lock.key %>" type="hidden" />
<input class="btn btn-danger btn-xs" type="submit" name="delete" value="<%= t('Delete') %>" data-confirm="<%= t('AreYouSure') %>" />
</form>
</td>
<td><a href="<%= root_path %>locks/<%= lock.key %>"><%= lock.key %></a></td>
<td><%= lock.info["lock"] %></td>
<td><%= lock.locked.count %></td>
<td><%= safe_relative_time(lock.created_at) %></td>
</tr>
</tbody>
<% end %>
</table>
<form action="<%= root_path %>locks/delete_all" method="get">
<input class="btn btn-danger btn-xs" type="submit" name="delete_all" value="<%= t('DeleteAll') %>" data-confirm="<%= t('AreYouSure') %>" />
Expand Down
2 changes: 1 addition & 1 deletion spec/sidekiq_unique_jobs/changelog_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@
let(:page_size) { 1 }

context "when no entries exist" do
it { is_expected.to match_array([0, "0", []]) }
it { is_expected.to match_array([0, 0, []]) }
end

context "when entries exist" do
Expand Down
Loading

0 comments on commit fd3d83e

Please sign in to comment.