Skip to content
This repository has been archived by the owner on Jun 9, 2022. It is now read-only.

Load list of slugs lazily #59

Open
5 tasks
tobinus opened this issue Aug 18, 2016 · 0 comments
Open
5 tasks

Load list of slugs lazily #59

tobinus opened this issue Aug 18, 2016 · 0 comments

Comments

@tobinus
Copy link
Member

tobinus commented Aug 18, 2016

Even if the list of slugs isn't used, it is currently loaded from the database every time an instance of SlugList is made. Finding the slugs requires a full scan of the table slug_to_slug, which is wasteful if it's not going to be used.

A better approach would be to only fetch the list of slugs once requested.

  • Store slugs from constructor in self._slugs
  • Use self._slugs in canonical_slug (so it won't trigger fetching the list of slugs)
  • Fetch and return list of slugs from the database when self.slugs is referenced.
  • Do so only the first time self.slugs is referenced, and populate self._slugs. On subsequent references, return self._slugs.
  • Don't fetch list of slugs in SlugList.from_slug().
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant