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

permanent flag is not avoiding computation of slug #14

Open
ivanseidel opened this issue Oct 4, 2018 · 2 comments
Open

permanent flag is not avoiding computation of slug #14

ivanseidel opened this issue Oct 4, 2018 · 2 comments

Comments

@ivanseidel
Copy link

ivanseidel commented Oct 4, 2018

} else {
if (item.isShortIdMode) {
makeUniqueShortIdSlug(doc, item.name, values, opts, function (err, slug) {
if (!doc[item.name] || !(item.permanent && doc[item.name])) {
doc[item.name] = slug;
}
callback();
})
} else {
makeUniqueCounterSlug(doc, item.name, values, opts, item.padding , function (err, slug) {
if (!doc[item.name] || !(item.permanent && doc[item.name])) {
doc[item.name] = slug;
}
callback();
})
}

Method makeUniqueCounterSlug is being called before regardless of the necessity to re-create slug.

For instance:

  • I have a document with an unique slug already set based on title
  • The title changes and the doc gets saved
  • The plugin will call makeUniqueCounterSlug (because the path has been modified)
  • The plugin will check later if permanent flag is set and there is already an value set on it

It will not update the slug, although it did process the slug string and made a query on db.

Should this be avoided? if so, I can try to swap the order of the checking/generation and submit a merge request.

@YuriGor
Copy link

YuriGor commented Oct 25, 2018

I fixed this in my fork by moving check of permanent flag up

@ivanseidel
Copy link
Author

Here too @YuriGor: https://github.com/TendaDigital/mongoose-slug-generator

you can use yarn add @tenda.digital/mongoose-slug-generator

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