Permalink
Browse files

* update amount in account record to make queries faster (saves 7sec …

…on accounts page today)
  • Loading branch information...
1 parent 546ddca commit 4dd4e22de46764674a303a398aa1f3b64ded74fc Thies C. Arntzen committed Mar 30, 2010
Showing with 11 additions and 1 deletion.
  1. +3 −0 db/schema.rb
  2. +8 −1 lib/acts_as_account/journal.rb
View
@@ -9,6 +9,9 @@
t.integer "holder_id", :null => false
t.string "holder_type", :null => false
t.string "name", :null => false
+
+ t.integer "amount", :default => 0
+
t.datetime "created_at"
t.datetime "updated_at"
end
@@ -22,20 +22,27 @@ def clear_current
def transfer(amount, from_account, to_account, reference = nil, valuta = Time.now)
transaction do
logger.debug { "ActsAsAccount::Journal.transfer amount: #{amount} from:#{from_account.id} to:#{to_account.id} reference:#{reference.class.name}(#{reference.id}) valuta:#{valuta}" } if logger
+
+ from_account.lock!
+ to_account.lock!
postings.build(
:amount => amount * -1,
:account => from_account,
:other_account => to_account,
:reference => reference,
:valuta => valuta).save_without_validation
-
+
+
postings.build(
:amount => amount,
:account => to_account,
:other_account => from_account,
:reference => reference,
:valuta => valuta).save_without_validation
+
+ from_account.increment!(:amount, -amount)
+ to_account.increment!(:amount, amount)
end
end
end

0 comments on commit 4dd4e22

Please sign in to comment.