perf(income statement): cache income statement queries #2371

Merged
zachgoll merged 5 commits from zachgoll/perf-budget-category into main 2025-06-15 22:09:46 +08:00
zachgoll commented 2025-06-15 21:51:55 +08:00 (Migrated from github.com)

This PR is a temporary fix for the slow income statement queries that are causing huge slowdowns on the budget and transaction pages.

  • Stores income statement aggregations in the cache
  • "Warms" the cache after every sync to avoid a slow first page load

Before (both warm + cold perform poorly):

Type IPS Deviation Time/Iteration Iterations Total Time
COLD 0.037 ± 0.00% 26.76 s/i 1.000 26.758725s
WARM 0.038 ± 0.00% 26.63 s/i 1.000 26.628038s

After (cold query still inefficient, but subsequent runs significantly faster):

Type IPS Deviation Time/Iteration Iterations Total Time
COLD 0.036 ± 0.00% 27.68 s/i 1.000 27.682548s
WARM 2.977 ± 0.00% 335.90 ms/i 30.000 10.153693s

This PR does not address the core issue of the inefficient query. We will push a future fix to address that.

This PR is a _temporary_ fix for the slow income statement queries that are causing huge slowdowns on the budget and transaction pages. - Stores income statement aggregations in the cache - "Warms" the cache after every sync to avoid a slow first page load Before (both warm + cold perform poorly): | Type | IPS | Deviation | Time/Iteration | Iterations | Total Time | |------|-----|-----------|----------------|------------|------------| | COLD | 0.037 | ± 0.00% | 26.76 s/i | 1.000 | 26.758725s | | WARM | 0.038 | ± 0.00% | 26.63 s/i | 1.000 | 26.628038s | After (cold query still inefficient, but subsequent runs significantly faster): | Type | IPS | Deviation | Time/Iteration | Iterations | Total Time | |------|-----|-----------|----------------|------------|------------| | COLD | 0.036 | ± 0.00% | 27.68 s/i | 1.000 | 27.682548s | | WARM | 2.977 | ± 0.00% | 335.90 ms/i | 30.000 | 10.153693s | This PR does not address the core issue of the inefficient query. We will push a future fix to address that.
cursor[bot] (Migrated from github.com) reviewed 2025-06-15 21:55:15 +08:00
cursor[bot] (Migrated from github.com) left a comment

Bug: IncomeStatement Sync Fails Due to Private Method Access

The code attempts to call the private methods family_stats and category_stats on an IncomeStatement instance. This external call to private methods will raise a NoMethodError, causing the intended cache warming to fail during the sync process.

app/models/account/syncer.rb#L19-L22

8cafbc7f83/app/models/account/syncer.rb (L19-L22)

Fix in Cursor


Bug: API Method Visibility Change

The generate_multi_currency_data! method is no longer publicly accessible. Previously defined in the private section and exposed via a Demo::Generator.class_eval block, it was removed during refactoring. Unlike other methods that were moved to the public section, generate_multi_currency_data! was not, and its class_eval exposure was also removed, breaking the public API.

app/models/demo/generator.rb#L109-L1223

8cafbc7f83/app/models/demo/generator.rb (L109-L1223)

Fix in Cursor


Was this report helpful? Give feedback by reacting with 👍 or 👎

<details open> <summary><h3>Bug: IncomeStatement Sync Fails Due to Private Method Access</h3></summary> The code attempts to call the private methods `family_stats` and `category_stats` on an `IncomeStatement` instance. This external call to private methods will raise a `NoMethodError`, causing the intended cache warming to fail during the sync process. <p></p> <details> <summary><code>app/models/account/syncer.rb#L19-L22</code></summary> https://github.com/maybe-finance/maybe/blob/8cafbc7f832c59358a11e5134f98605327697f06/app/models/account/syncer.rb#L19-L22 </details> <a href="https://cursor.com/open?data=eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6ImJ1Z2JvdC12MSJ9.eyJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9DVVJTT1IiLCJkYXRhIjp7ImJ1ZyI6ImV5SnNiMk5oZEdsdmJuTWlPbHQ3SW1acGJHVWlPaUpoY0hBdmJXOWtaV3h6TDJGalkyOTFiblF2YzNsdVkyVnlMbkppSWl3aWMzUmhjblJNYVc1bElqb3hPU3dpWlc1a1RHbHVaU0k2TWpJc0ltTnZaR1ZNYVc1bGN5STZXMTE5WFN3aWFXUWlPaUl6WmpJek1tTTVZUzFqTXpsaExUUmpNVEF0T1dNeE5DMHdPRFl6Tm1NeU1UUTRaR1lpTENKa1pYTmpjbWx3ZEdsdmJpSTZJbFJvWlNCamIyUmxJR0YwZEdWdGNIUnpJSFJ2SUdOaGJHd2dkR2hsSUhCeWFYWmhkR1VnYldWMGFHOWtjeUJnWm1GdGFXeDVYM04wWVhSellDQmhibVFnWUdOaGRHVm5iM0o1WDNOMFlYUnpZQ0J2YmlCaGJpQmdTVzVqYjIxbFUzUmhkR1Z0Wlc1MFlDQnBibk4wWVc1alpTNGdWR2hwY3lCbGVIUmxjbTVoYkNCallXeHNJSFJ2SUhCeWFYWmhkR1VnYldWMGFHOWtjeUIzYVd4c0lISmhhWE5sSUdFZ1lFNXZUV1YwYUc5a1JYSnliM0pnTENCallYVnphVzVuSUhSb1pTQnBiblJsYm1SbFpDQmpZV05vWlNCM1lYSnRhVzVuSUhSdklHWmhhV3dnWkhWeWFXNW5JSFJvWlNCemVXNWpJSEJ5YjJObGMzTXVJaXdpWTI5dVptbGtaVzVqWlNJNk1DNHpOamN6TkRRMk5EUXlOekF3TmpNeExDSmpZWFJsWjI5eWVTSTZJa3hQUjBsRFgwSlZSeUo5IiwiYnJhbmNoIjoiemFjaGdvbGwvcGVyZi1idWRnZXQtY2F0ZWdvcnkifSwiaWF0IjoxNzQ5OTk1NzE1LCJleHAiOjE3NTA2MDA1MTV9.Toa8vl4qW3Ns1j44S5XOY9WrJAnV3_LRWjsk5t4OSgXzBD5VC0djZxwdNPg_6xjnXzWI9IvX1Zf2HvLos_AXcCwkrqD-rHkvCgeosPHMV_VonQTf_tAtR4xWAEvb8imRrIFdbmw3ZZqIilwXGKoTiYaIRArj7HJ4KtFnkX6UYz_sDmGTzdEO8dpA_2SMLyASBQXMTstevPPhkj_spznOsZPn2dZr10KmL4lfNPuU3bHJKS0fzuoOxi49O3XhZBIJ0X_mhGzyE7Kc7HNvQGkatOpoZr6qEJfSl-IryZNmmNw_TjyK8cdd8HPTaVnMBHS2tsFVVfjatT-hbi4Lk15mpg">Fix in Cursor</a> </details> --- <details open> <summary><h3>Bug: API Method Visibility Change</h3></summary> The `generate_multi_currency_data!` method is no longer publicly accessible. Previously defined in the private section and exposed via a `Demo::Generator.class_eval` block, it was removed during refactoring. Unlike other methods that were moved to the public section, `generate_multi_currency_data!` was not, and its `class_eval` exposure was also removed, breaking the public API. <p></p> <details> <summary><code>app/models/demo/generator.rb#L109-L1223</code></summary> https://github.com/maybe-finance/maybe/blob/8cafbc7f832c59358a11e5134f98605327697f06/app/models/demo/generator.rb#L109-L1223 </details> <a href="https://cursor.com/open?data=eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6ImJ1Z2JvdC12MSJ9.eyJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9DVVJTT1IiLCJkYXRhIjp7ImJ1ZyI6ImV5SnNiMk5oZEdsdmJuTWlPbHQ3SW1acGJHVWlPaUpoY0hBdmJXOWtaV3h6TDJSbGJXOHZaMlZ1WlhKaGRHOXlMbkppSWl3aWMzUmhjblJNYVc1bElqb3hNRGtzSW1WdVpFeHBibVVpT2pFeU1qTXNJbU52WkdWTWFXNWxjeUk2VzExOVhTd2lhV1FpT2lJM1ptSTBOalkxT1MxaU1UUTJMVFJpTVRBdE9URTRNUzB5T1daaU5ERTRNRFkwTW1FaUxDSmtaWE5qY21sd2RHbHZiaUk2SWxSb1pTQmdaMlZ1WlhKaGRHVmZiWFZzZEdsZlkzVnljbVZ1WTNsZlpHRjBZU0ZnSUcxbGRHaHZaQ0JwY3lCdWJ5QnNiMjVuWlhJZ2NIVmliR2xqYkhrZ1lXTmpaWE56YVdKc1pTNGdVSEpsZG1sdmRYTnNlU0JrWldacGJtVmtJR2x1SUhSb1pTQndjbWwyWVhSbElITmxZM1JwYjI0Z1lXNWtJR1Y0Y0c5elpXUWdkbWxoSUdFZ1lFUmxiVzg2T2tkbGJtVnlZWFJ2Y2k1amJHRnpjMTlsZG1Gc1lDQmliRzlqYXl3Z2FYUWdkMkZ6SUhKbGJXOTJaV1FnWkhWeWFXNW5JSEpsWm1GamRHOXlhVzVuTGlCVmJteHBhMlVnYjNSb1pYSWdiV1YwYUc5a2N5QjBhR0YwSUhkbGNtVWdiVzkyWldRZ2RHOGdkR2hsSUhCMVlteHBZeUJ6WldOMGFXOXVMQ0JnWjJWdVpYSmhkR1ZmYlhWc2RHbGZZM1Z5Y21WdVkzbGZaR0YwWVNGZ0lIZGhjeUJ1YjNRc0lHRnVaQ0JwZEhNZ1lHTnNZWE56WDJWMllXeGdJR1Y0Y0c5emRYSmxJSGRoY3lCaGJITnZJSEpsYlc5MlpXUXNJR0p5WldGcmFXNW5JSFJvWlNCd2RXSnNhV01nUVZCSkxpSXNJbU52Ym1acFpHVnVZMlVpT2pBdU16WXhOemMyTkRRd016WTRNamd4T1N3aVkyRjBaV2R2Y25raU9pSk1UMGRKUTE5Q1ZVY2lmUSIsImJyYW5jaCI6InphY2hnb2xsL3BlcmYtYnVkZ2V0LWNhdGVnb3J5In0sImlhdCI6MTc0OTk5NTcxNSwiZXhwIjoxNzUwNjAwNTE1fQ.fZnlWiyaEB4sr5NgH-PyDglCrLeDlUBCiljFyaTB_UIWQ2FWxBvW0AB1FBpU0TLKrDPApSsMeX5JHJStQBVqk47N5v6ooBeOix6YEjmQJjHeQeOp-xy4-yeBrKu1NDcl89HKNO2dVgQeswq6YkXEU_hhc66jsd6SwrLYRi-hOJuhHIk0h6OuLAUS1EWpesxr8pWJMaIvotUGJheb4egmXOgsytVyaeeVgxfM0fiIyCWE_hryUQxCg95WnCU6FkllqpO65WoEiPvat9k_IeMAJ82P6hofui_VueBgrPsUXzmDYyF-3bFjiXAzngj9-5fVgmrjIjzWWPgRD4fner7fYA">Fix in Cursor</a> </details> --- _Was this report helpful? Give feedback by reacting with 👍 or 👎_
cursor[bot] (Migrated from github.com) reviewed 2025-06-15 22:04:12 +08:00
cursor[bot] (Migrated from github.com) left a comment

BugBot reviewed your changes and found no bugs!


Was this report helpful? Give feedback by reacting with 👍 or 👎

### ✅ BugBot reviewed your changes and found no bugs! --- _Was this report helpful? Give feedback by reacting with 👍 or 👎_
Sign in to join this conversation.