mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-08-08 06:55:21 +02:00
Use visible
sync logic in sidebar groups
This commit is contained in:
parent
894fda9659
commit
f0e348c728
2 changed files with 7 additions and 2 deletions
|
@ -107,7 +107,11 @@ class BalanceSheet
|
||||||
def totals_query
|
def totals_query
|
||||||
@totals_query ||= active_accounts
|
@totals_query ||= active_accounts
|
||||||
.joins(ActiveRecord::Base.sanitize_sql_array([ "LEFT JOIN exchange_rates ON exchange_rates.date = CURRENT_DATE AND accounts.currency = exchange_rates.from_currency AND exchange_rates.to_currency = ?", currency ]))
|
.joins(ActiveRecord::Base.sanitize_sql_array([ "LEFT JOIN exchange_rates ON exchange_rates.date = CURRENT_DATE AND accounts.currency = exchange_rates.from_currency AND exchange_rates.to_currency = ?", currency ]))
|
||||||
.joins("LEFT JOIN syncs ON syncs.syncable_id = accounts.id AND syncs.syncable_type = 'Account' AND (syncs.status = 'pending' OR syncs.status = 'syncing')")
|
.joins(ActiveRecord::Base.sanitize_sql_array([
|
||||||
|
"LEFT JOIN syncs ON syncs.syncable_id = accounts.id AND syncs.syncable_type = 'Account' AND syncs.status IN (?) AND syncs.created_at > ?",
|
||||||
|
%w[pending syncing],
|
||||||
|
Sync::VISIBLE_FOR.ago
|
||||||
|
]))
|
||||||
.select(
|
.select(
|
||||||
"accounts.*",
|
"accounts.*",
|
||||||
"SUM(accounts.balance * COALESCE(exchange_rates.rate, 1)) as converted_balance",
|
"SUM(accounts.balance * COALESCE(exchange_rates.rate, 1)) as converted_balance",
|
||||||
|
|
|
@ -16,8 +16,9 @@ class Sync < ApplicationRecord
|
||||||
has_many :children, class_name: "Sync", foreign_key: :parent_id, dependent: :destroy
|
has_many :children, class_name: "Sync", foreign_key: :parent_id, dependent: :destroy
|
||||||
|
|
||||||
scope :ordered, -> { order(created_at: :desc) }
|
scope :ordered, -> { order(created_at: :desc) }
|
||||||
scope :incomplete, -> { where("syncs.status IN (?)", [ :pending, :syncing ]) }
|
scope :incomplete, -> { where("syncs.status IN (?)", %w[pending syncing]) }
|
||||||
scope :visible, -> { incomplete.where("syncs.created_at > ?", VISIBLE_FOR.ago) }
|
scope :visible, -> { incomplete.where("syncs.created_at > ?", VISIBLE_FOR.ago) }
|
||||||
|
|
||||||
# In-flight records that have exceeded the allowed runtime
|
# In-flight records that have exceeded the allowed runtime
|
||||||
scope :stale_candidates, -> { incomplete.where("syncs.created_at < ?", STALE_AFTER.ago) }
|
scope :stale_candidates, -> { incomplete.where("syncs.created_at < ?", STALE_AFTER.ago) }
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue