duncanmcclean / simple-commerce

A simple, yet powerful e-commerce addon for Statamic.
https://statamic.com/addons/duncanmcclean/simple-commerce
Other
143 stars 37 forks source link

`sc:countries` performance issues. #1146

Open sbrow opened 2 weeks ago

sbrow commented 2 weeks ago

Description

I was looking into why my /checkout/information page took so long to load. It turns out that, according to the DebugBar, nearly 90% of the load time was spent rendering {{ sc:countries }} tags for the shipping and billing address. This takes over 5 seconds on my intel i7-1260P.

image

Steps to reproduce

  1. Clone the starter kit
  2. Turn on the debug bar
  3. add a product to the cart
  4. Continue checkout until the information page.
  5. View the load times

Environment

Environment Application Name: <REDACTED> Laravel Version: 11.20.0 PHP Version: 8.2.13 Composer Version: 2.6.5 Environment: local Debug Mode: ENABLED URL: <REDACTED>.test Maintenance Mode: OFF Timezone: America/New_York Locale: en

Cache Config: NOT CACHED Events: NOT CACHED Routes: NOT CACHED Views: CACHED

Drivers Broadcasting: null Cache: file Database: mysql Logs: stack / single Mail: smtp Queue: sync Session: file

Simple Commerce Currencies: USD Gateways: Stripe Repository: Customer: DuncanMcClean\SimpleCommerce\Customers\UserCustomerRepository Repository: Order: DuncanMcClean\SimpleCommerce\Orders\EntryOrderRepository Repository: Product: DuncanMcClean\SimpleCommerce\Products\EntryProductRepository Shipping Methods: Flat Rate Shipping, Free Shipping Tax Engine: DuncanMcClean\SimpleCommerce\Tax\Standard\TaxEngine

Sentry Enabled: MISSING DSN Environment: local Laravel SDK Version: 4.5.1 PHP SDK Version: 4.7.0 Release: NOT SET Sample Rate Errors: 100% Sample Rate Performance Monitoring: 100% Sample Rate Profiling: NOT SET Send Default PII: DISABLED

Statamic Addons: 8 Sites: 1 Stache Watcher: Enabled Static Caching: Disabled Version: 5.22.0 PRO

Statamic Addons arthurperton/wordpress-users: 1.2.0 duncanmcclean/guest-entries: 4.0.1 duncanmcclean/simple-commerce: 7.4.2 <REDACTED>/sc-affiliates: dev-8121e749b3eef1457b7bede10f2ddec0254748b4 <REDACTED>/sc-checkout: dev-8121e749b3eef1457b7bede10f2ddec0254748b4 <REDACTED>/sc-subscriptions: dev-8121e749b3eef1457b7bede10f2ddec0254748b4 sbrow/banner: dev-8121e749b3eef1457b7bede10f2ddec0254748b4 statamic/seo-pro: 6.0.3

duncanmcclean commented 2 weeks ago

Simple Commerce's Country field is being replaced by Statamic's Dictionary fieldtype in the next major version.

sbrow commented 2 weeks ago

Maybe I'm an idiot, but couldn't countries be saved in flat files? If they were publishable, then users could publish only the countries that they actually service. Then you could piggy-back off of built-in caching and indexing instead of having to roll your own. And instead of having to filter all the world's countries everywhere, you would only have to filter them in edge-cases. :man_shrugging:


iso: US
name: United States
regions:
  - id: us-ak
    name: Alaska
  - id: us-al
    name: Alabama
# ...
duncanmcclean commented 2 weeks ago

You could maybe try filtering down the returned countries with the only parameter: http://simple-commerce.duncanmcclean.com/tags/countries#content-only

sbrow commented 2 weeks ago

I was, but it still took forever. I've patched the problem by just hard-coding the countries I need.