ept/invoicing

known_subclasses _very_ slow in high throughput environments

Opened this issue · 2 comments

Hey Guys,

Not sure if this is even still maintained, given the age of the last release.

I thought I'd let you know that the current implementation of know subclasses on ledger / line items is very slow on large tables. Our production ledge table has ~ 400k rows, and our line item table has 1M plus.

It took a bit of digging to find this method being the source of slow down.

The fix for us was simple, we added the following methods to our base classes for ledger / line item.

  def self.known_subclasses(_table = table_name, _type_column = inheritance_column)
    InvoicingLineItem.descendants
  end
  def self.known_subclasses(_table = table_name, _type_column = inheritance_column)
    InvoicingLedgerItem.descendants
  end

The cause of the slow down is a bit subtle, since we are constantly building invoices, that means we are inserting / deleting from the line_item / ledger_item table constantly. The method in teh gem for determining known subclasses:

SELECT DISTICT type from ...

Has to acquire a table look in order to determine the distinct set of entries for that table. This causes queueing all over the place.

Anyway thought you'd like to know, as there is a huge TODO left on the code that causes this select.

@joegaudet there is updated version here https://github.com/code-mancers/invoicing. Can you try it and see if it works for your case. I can help you out with performance issues.

I assume this is the one that's published to rubygems?