Skip to content
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

known_subclasses _very_ slow in high throughput environments #13

Open
joegaudet opened this issue Sep 10, 2017 · 2 comments
Open

known_subclasses _very_ slow in high throughput environments #13

joegaudet opened this issue Sep 10, 2017 · 2 comments

Comments

@joegaudet
Copy link

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.

@iffyuva
Copy link
Collaborator

iffyuva commented Sep 11, 2017

@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.

@joegaudet
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants