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

Slug index creation not taking localization into account #242

Open
onomated opened this issue Jul 4, 2017 · 3 comments
Open

Slug index creation not taking localization into account #242

onomated opened this issue Jul 4, 2017 · 3 comments

Comments

@onomated
Copy link

onomated commented Jul 4, 2017

mongoid-slug: 5.3

I have a model Event with the following slug specification:

slug :title, history: true, localize: true

Getting several unoptimized queries (2-6 secs) due to full on COLLSCAN's in my Mongo logs during slug generation. A few examples below:

 I COMMAND  [conn811652042] query db.events query: { $or: [ { _slugs.en: { $in: [ "lationship" ] } } ] } planSummary: COLLSCAN ntoreturn:1 ntoskip:0 nscanned:0 nscannedObjects:325827 keyUpdates:0 writeConflicts:0 numYields:2593 nreturned:0 reslen:20 locks:{ Global: { acquireCount: { r: 5188 } }, MMAPV1Journal: { acquireCount: { r: 2594 } }, Database: { acquireCount: { r: 2594 } }, Collection: { acquireCount: { R: 2594 } } } 1529ms

 I COMMAND  [conn810189219] query db.events query: { _slugs.en: { $all: [ /^new\-phone(?:-(\d+))?$/m ] }, _id: { $ne: ObjectId('<redacted>') } } planSummary: IXSCAN { _id: 1 } ntoreturn:0 ntoskip:0 nscanned:325596 nscannedObjects:325596 keyUpdates:0 writeConflicts:0 numYields:4610 nreturned:33 reslen:25751 locks:{ Global: { acquireCount: { r: 9222 } }, MMAPV1Journal: { acquireCount: { r: 4613 }, acquireWaitCount: { r: 1 }, timeAcquiringMicros: { r: 8420 } }, Database: { acquireCount: { r: 4611 } }, Collection: { acquireCount: { R: 4611 }, acquireWaitCount: { R: 2 }, timeAcquiringMicros: { R: 8592 } } } 6013ms

Mongoid slug creates an index on the _slug field, not the slug.en field. Indices should at least be created on the slug I18n.default_locale field. Also, is there way way to override the default index created?

@dblock
Copy link
Collaborator

dblock commented Jul 5, 2017

Dup of #184? Either way definitely looks like a pretty gross omission, would love an implementation.

@onomated
Copy link
Author

onomated commented Jul 5, 2017

Different issue from #184.
I'm trying to figure the best approach for this since there is no way to tell what locales clients support when localize is specified. Either we allow clients specify the locales they support so indices are created accordingly? Or have an option to disable index creation and let clients specify their indices based on recommendations. Both options may work as well.
For option 1, I'm thinking something along the lines of:

  • localize: true: This creates an index on _slug.<I18n.default_locale> field
  • localize: [:en, :de, :es,...]: Creates indices the specified locales.

@dblock Thoughts?

@dblock
Copy link
Collaborator

dblock commented Jul 6, 2017

I think we should be able to disable index creation or override what kind of index is being created here, would take a PR for that, opened #244 to track.

I think your locale suggestions make total sense, same deal.

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

No branches or pull requests

2 participants