-
Notifications
You must be signed in to change notification settings - Fork 73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement search by pattern for Mapping Rules #1239
Conversation
Screen capture? |
@thomasmaas ☝️ |
681a8b1
to
3c11f33
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👏 🥇 💪
app/models/proxy_rule.rb
Outdated
@@ -25,6 +28,16 @@ class ProxyRule < ApplicationRecord | |||
|
|||
ALLOWED_HTTP_METHODS = %w[GET POST DELETE PUT PATCH HEAD OPTIONS].freeze | |||
|
|||
scope :by_query, ->(query, owner_type, owner_id) do | |||
return if query.blank? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return if query.blank? | |
return none if query.blank? |
Not sure if it will work, but then this way we return the same time and we can chain scopes... so it won't be null anymore. Btw, lambda checks that the params are passed so 'query' should never be nil 🤔 so imo we shouldn't even have this checking the type at all
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My first shoot was returning a none
relation. But it doesn't work because it ignores prepended and postponed relations in the query. eg:
with return none ..
[1] pry(main)> ProxyRule.by_query('', 'Proxy', 22).where(position: 2).to_sql
=> ""
it returned the empty relation and ignored the where position.
with return nil
[1] pry(main)> ProxyRule.by_query('', 'Proxy', 22).where(position: 2).to_sql
=> "SELECT `proxy_rules`.* FROM `proxy_rules` WHERE `proxy_rules`.`position` = 2"
it skipped the where(id: ..) and made the where(position: )
one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be a query see app/queries
I prefer not mixing scopes with other stuffs.
3c11f33
to
3745336
Compare
Codecov Report
@@ Coverage Diff @@
## master #1239 +/- ##
==========================================
+ Coverage 86.29% 91.54% +5.24%
==========================================
Files 2139 2265 +126
Lines 66794 73359 +6565
==========================================
+ Hits 57640 67154 +9514
+ Misses 9154 6205 -2949
Continue to review full report at Codecov.
|
d6384bf
to
04017d5
Compare
@@ -0,0 +1,4 @@ | |||
# frozen_string_literal: true | |||
|
|||
class ApplicationJob < ActiveJob::Base |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😂 😂 😂 😂 😂
Cadu 1 - RuboCop 0
@@ -36,6 +36,10 @@ def initialize(a,b,c) | |||
|
|||
transactional = non_transactional.map {|t| "~#{t}" } | |||
|
|||
Before do | |||
IndexProxyRuleWorker.stubs(:perform_later) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Martouta
It is run after_commit, so all tests with disable_transactional_fixtures
and involving Proxy (basically all, because you create an account + service + proxy) will trigger indexation of Proxy.
We wanted to use ActiveJob::TestHelper perform_enqueued_jobs
but it does not have the :only
options in Rails 4.2, we need to update to rails 5.x (see the monkey patch)
And anyway it is big task to change it everywhere, so it is acceptable to have it now
We need to move all workers to ActiveJob, not the purpose of this PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, cucumber enables Sidekiq.inline! for all features, without this, all cucumber tests fails
# TODO: Remove this Monkey patch after we move to Rails 5. | ||
# This is used to ensure that we run only a specific job in a Test. | ||
# It was extracted from | ||
# https://github.com/rails/rails/blob/fc5dd0b85189811062c85520fd70de8389b55aeb/activejob/lib/active_job/test_helper.rb#L368 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is acceptable! Really :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better idea not to mix models scopes and search queries
Since you are going to push again anyway, personally I'd appreciate if the update/install of Gems could be a separate commit before the actual changes in the code 😄 |
This commit upgrades thinking sphinx gem. The new version added the ability to filter using string types, avoinding us to save it using a CRC32 version of the string. This commit also upgrades minitest.
e348ef0
to
e9c43b7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Amazing job! 👏 🥇 💪
dd257ec
e9c43b7
to
dd257ec
Compare
app/queries/proxy_rule_query.rb
Outdated
scope = scope.order_by(@sort, @direction).includes(:metric) | ||
return scope if query.blank? | ||
options = { | ||
ids_only: true, star: true, per_page: 1_000_000, ignore_scopes: true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1 million per page? Are you sure?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah.. don't make sense haha.. will add the same maximum as we paginate.
dd257ec
to
58ef668
Compare
app/queries/proxy_rule_query.rb
Outdated
scope = scope.order_by(@sort, @direction).includes(:metric) | ||
return scope if query.blank? | ||
options = { | ||
ids_only: true, star: true, per_page: 20, ignore_scopes: true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ouch I dis not check correctly
The per page does not use the variable in. Initialize
This commit implements a search by pattern for mapping rules. It includes a search field in the mapping rules page for both Backend APIs and Services. It also adds an index for ProxyRule class using Sphinx.
58ef668
to
4c62160
Compare
This commit implements a search by pattern for mapping rules. It
includes a search field in the mapping rules page for both Backend
APIs and Services. It also adds an index for ProxyRule class using
Sphinx.