Skip to content

Commit

Permalink
Merge pull request #587 from workarea-commerce/upgrade-gems
Browse files Browse the repository at this point in the history
Upgrade gems
  • Loading branch information
Ben Crouse authored Jan 29, 2021
2 parents f042d3a + b7ad7cb commit b36cf58
Show file tree
Hide file tree
Showing 22 changed files with 43 additions and 159 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def condition_options
end

def selected_condition_option
if order_total?
if use_order_total?
'order_total'
elsif user_tag?
'user_tag'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def condition_options
end

def selected_condition_option
if order_total?
if use_order_total?
'order_total'
elsif item_quantity?
'item_quantity'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def condition_options
end

def selected_condition_option
if order_total?
if use_order_total?
'order_total'
elsif user_tag?
'user_tag'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def condition_options
end

def selected_condition_option
if order_total?
if use_order_total?
'order_total'
elsif user_tag?
'user_tag'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def condition_options
end

def selected_condition_option
if order_total?
if use_order_total?
'order_total'
elsif item_quantity?
'item_quantity'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def condition_options
end

def selected_condition_option
if order_total?
if use_order_total?
'order_total'
elsif item_quantity?
'item_quantity'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def condition_options
end

def selected_condition_option
if order_total?
if use_order_total?
'order_total'
elsif user_tag?
'user_tag'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def condition_options
end

def selected_condition_option
if order_total?
if use_order_total?
'order_total'
elsif user_tag?
'user_tag'
Expand Down
4 changes: 1 addition & 3 deletions core/app/models/workarea/content.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ class Content
after_update :touch_contentable

scope :recent, ->(l = 5) { order_by([:created_at, :desc]).limit(l) }
scope :system, (lambda do
any_of({ :contentable_type.exists => false }, { contentable_type: nil })
end)
scope :system, -> { where(contentable_type: nil) }

# Find {Content} for a given object. Object
# can be string or model (polymorphic).
Expand Down
2 changes: 1 addition & 1 deletion core/app/models/workarea/metrics/revenue_change.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module RevenueChange

module ClassMethods
def revenue_change_median
sort = if scoped.selector.merge(declined_revenue.selector) == scoped.selector
sort = if scoped.selector.present? && scoped.selector <= declined_revenue.selector
:desc
else
:asc
Expand Down
72 changes: 0 additions & 72 deletions core/app/models/workarea/order/queries.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,78 +123,6 @@ def average_order_value(start_time = 30.years.ago, end_time = Time.current)

Money.new(cents || 0)
end

# TODO: Remove in an appropriate future version; no longer used in Base
def abandoned_count(start_time = 30.years.ago, end_time = Time.current)
Order
.where(:created_at.lte => Workarea.config.order_active_period.ago)
.where(:created_at.gte => start_time, :created_at.lt => end_time)
.where(:'items.0.sku'.exists => true)
.any_of({ placed_at: nil }, { :placed_at.exists => false })
.count
end

# TODO: Remove in an appropriate future version; no longer used in Base
def abandoned_value(start_time = 30.years.ago, end_time = Time.current)
cents = Order
.where(:created_at.lte => Workarea.config.order_active_period.ago)
.where(:created_at.gte => start_time, :created_at.lt => end_time)
.any_of({ placed_at: nil }, { :placed_at.exists => false })
.sum('total_value.cents')

Money.new(cents || 0)
end

# TODO: Remove in an appropriate future version; no longer used in Base
def abandoned_product_ids(start_time = 30.years.ago, end_time = Time.current, limit = 5)
results = Order.collection.aggregate([
{
'$match' => {
'$and' => [
{
'created_at' => {
'$gte' => Time.mongoize(start_time),
'$lt' => Time.mongoize(end_time)
}
},
{
'created_at' => { '$lte' => Time.mongoize(Workarea.config.order_active_period.ago) }
}
],
'$or' => [
{ 'placed_at' => nil },
{ 'placed_at' => { '$exists' => false } }
],
'items.0.sku' => { '$exists' => true }
},
},
{
'$unwind' => '$items'
},
{
'$group' => {
'_id' => '$items.product_id',
'total' => { '$sum' => '$items.total_value.cents' },
'count' => { '$sum' => 1 }
}
},
{
'$sort' => { 'count' => -1 }
},
{
'$limit' => limit
}
])

results.reduce({}) do |memo, result|
memo.merge!(
result['_id'] => {
count: result['count'],
total: Money.new(result['total'])
}
)
end
end
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ module OrderTotal
#
# @return [Boolean]
#
def order_total?
def use_order_total?
order_total.present? && order_total > 0
end

Expand All @@ -36,7 +36,7 @@ def order_total?
# @return [Boolean]
#
def order_total_qualifies?(order)
return true unless order_total?
return true unless use_order_total?

if order_total_operator == :less_than
order.subtotal_price < order_total
Expand Down
2 changes: 1 addition & 1 deletion core/app/models/workarea/releasable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ module Releasable
end

def changesets_with_children
criteria = Release::Changeset.any_of(
criteria = Release::Changeset.or(
{ releasable_type: self.class.name, releasable_id: id }
)

Expand Down
8 changes: 2 additions & 6 deletions core/app/models/workarea/release.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ class Release
after_save :reset_preview
before_destroy :remove_publish_job

scope :not_published, (lambda do
any_of({ :published_at.exists => false }, { published_at: nil })
end)
scope :not_published, -> { where(published_at: nil) }
scope :published, (lambda do
where(:published_at.exists => true)
end)
Expand All @@ -40,9 +38,7 @@ class Release
:published_at.lte => ends_at
)
end
scope :not_scheduled, (lambda do
any_of({ :publish_at.exists => false }, { publish_at: nil })
end)
scope :not_scheduled, -> { where(publish_at: nil) }
scope :scheduled, ->(before: nil, after: nil) do
criteria = where(:publish_at.gt => Time.current)
criteria = criteria.where(:publish_at.lte => before) if before.present?
Expand Down
2 changes: 1 addition & 1 deletion core/app/models/workarea/tax/category.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def find_rate(price, country, region, postal_code)
end

def tiered?
@tiered ||= rates.or(
@tiered ||= rates.any_of(
{ :'tier_min.cents'.exists => true },
{ :'tier_max.cents'.exists => true }
).exists?
Expand Down
2 changes: 2 additions & 0 deletions core/app/models/workarea/tax/rate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ class Rate
index({ country: 1 })
index({ region: 1 })
index({ postal_code: 1 })
index({ 'tier_min.cents': 1 })
index({ 'tier_max.cents': 1 })

belongs_to :category,
class_name: 'Workarea::Tax::Category',
Expand Down
9 changes: 9 additions & 0 deletions core/lib/workarea/configuration/sidekiq.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@ def load
def configure_workarea!
::Sidekiq.configure_server do |config|
config.server_middleware do |chain|
chain.add SidekiqUniqueJobs::Middleware::Server
chain.add I18nServerMiddleware
chain.add AuditLogServerMiddleware
chain.add ReleaseServerMiddleware
end

config.client_middleware do |chain|
chain.add SidekiqUniqueJobs::Middleware::Client
chain.add I18nClientMiddleware
chain.add AuditLogClientMiddleware
end
Expand All @@ -40,10 +42,17 @@ def configure_workarea!
size: pool_size,
pool_timeout: pool_timeout
}

# From the sidekiq-unique-jobs README
config.death_handlers << lambda do |job, ex|
digest = job['lock_digest']
SidekiqUniqueJobs::Digests.new.delete_by_digest(digest) if digest
end
end

::Sidekiq.configure_client do |config|
config.client_middleware do |chain|
chain.add SidekiqUniqueJobs::Middleware::Client
chain.add Workarea::I18nClientMiddleware
chain.add AuditLogClientMiddleware
end
Expand Down
1 change: 0 additions & 1 deletion core/lib/workarea/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@
require 'workarea/ext/mongoid/list_field'
require 'workarea/ext/mongoid/each_by'
require 'workarea/ext/mongoid/except'
require 'workarea/ext/mongoid/moped_bson'
require 'workarea/ext/mongoid/timestamps_timeless'
require 'workarea/ext/mongoid/error'
require 'workarea/ext/mongoid/lookup_hash'
Expand Down
6 changes: 0 additions & 6 deletions core/lib/workarea/ext/mongoid/moped_bson.rb

This file was deleted.

42 changes: 0 additions & 42 deletions core/test/models/workarea/order/queries_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,48 +142,6 @@ def test_average_order_value
assert_equal(2.to_m, Order.average_order_value)
assert_equal(1.to_m, Order.average_order_value(2.hours.ago, Time.current))
end

# TODO: Remove; no longer used in Base
def test_abandoned_count
Order.create!(created_at: 4.hours.ago)
Order.create!(created_at: 1.hour.ago, items: [{ product_id: '1', sku: 2 }])
Order.create!(created_at: 4.hours.ago, items: [{ product_id: '1', sku: 2 }])
Order.create!(created_at: 8.hours.ago, items: [{ product_id: '1', sku: 2 }])
Order.create!(placed_at: 4.hours.ago, items: [{ product_id: '1', sku: 2 }])
Order.create!(created_at: 4.hours.ago, checkout_started_at: 5.hours.ago, items: [{ product_id: '1', sku: 2 }])

assert_equal(3, Order.abandoned_count)
assert_equal(2, Order.abandoned_count(5.hours.ago, Time.current))
end

# TODO: Remove; no longer used in Base
def test_abandoned_value
Order.create!(created_at: 3.hours.ago, items: [{ product_id: '1', sku: 2 }], total_value: 1.to_m)
Order.create!(created_at: 3.hours.ago, items: [{ product_id: '1', sku: 2 }], total_value: 1.to_m)
Order.create!(created_at: 5.hours.ago, items: [{ product_id: '1', sku: 2 }], total_value: 1.to_m)
Order.create!(placed_at: 3.hours.ago, items: [{ product_id: '1', sku: 2 }], total_value: 1.to_m)
Order.create!(checkout_started_at: 5.hours.ago, items: [{ product_id: '1', sku: 2 }], total_value: 1.to_m)

assert_equal(3.to_m, Order.abandoned_value)
assert_equal(2.to_m, Order.abandoned_value(5.hours.ago, Time.current))
end

# TODO: Remove; no longer used in Base
def test_abandoned_product_ids
Order.create!(items: [{ product_id: '3', sku: 2, total_value: 1 }])
Order.create!(created_at: 4.hours.ago, items: [{ product_id: '2', sku: 2, total_value: 1 }])
Order.create!(created_at: 4.hours.ago, items: [{ product_id: '1', sku: 2, total_value: 1 }])
Order.create!(created_at: 4.hours.ago, items: [{ product_id: '1', sku: 2, total_value: 1 }])
Order.create!(created_at: 8.hours.ago, items: [{ product_id: '1', sku: 2, total_value: 1 }])
Order.create!(placed_at: 3.hours.ago, items: [{ product_id: '2', sku: 2, total_value: 1 }])

group = {
'1' => { count: 3, total: 3.to_m },
'2' => { count: 1, total: 1.to_m }
}

assert_equal(group, Order.abandoned_product_ids)
end
end
end
end
Loading

0 comments on commit b36cf58

Please sign in to comment.