-
Notifications
You must be signed in to change notification settings - Fork 11
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
Product relations for categories #353
Conversation
) | ||
->withoutGlobalScopes() | ||
->whereIn((new(config('rapidez.models.category_product')))->qualifyColumn('visibility'), [2, 4]); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't very DRY, is there maybe a nice way to combine productIndices
into this relation?
Maybe |
From what I understand using withPivot would only add the visibility information (i.e. the extra information that's inside the pivot table) to the query, which we also already have for the products, so I'm not sure how it'd help here as it wouldn't improve efficiency in any way. I tried looking for an |
Mm, maybe a rename, |
src/Models/CategoryProduct.php
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CategoryProduct may conflict in name as there, i personally tend to stick close to the original table name like seen here https://github.com/Genaker/laragento/tree/main/src/Models
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's tough because then we also should rename the Product and Category models to CatalogProduct and CatalogCategory. With how it's set up right now, I feel like this one specifically is more consistent with the others and if this is something we want to uphold in the future we should probably change this in a dedicated PR so it shows up in the changelog.
I've removed |
As it turns out, we can use the
catalog_category_product_index_storeX
tables which contains the visibilities of the products. This gives a ~4x speedup in the query if you just want a products count, as joining the whole flat table is pretty slow™. To make this easy I've just added aproductIndices
relation along with theproducts
index to use in your withCount.