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

[performance] Looking up every file is slow #25

Open
pedro-psb opened this issue May 10, 2024 · 1 comment · May be fixed by #26
Open

[performance] Looking up every file is slow #25

pedro-psb opened this issue May 10, 2024 · 1 comment · May be fixed by #26

Comments

@pedro-psb
Copy link

pedro-psb commented May 10, 2024

Hello, I've noticed that the processing here can significantly slows down building the docs, probably because of BeautifulSoup.

On my website, running the plugin added an overhead of about 27s. Because I know the files where I want the swagger-ui tags to be used, I've added a simple filename filter patch to avoid trying to lookup on every single file. That improved the performance to only 2s!

def on_post_page(self, output, page, config, **kwargs):
    """Replace swagger-ui tag with iframe
    Add javascript code to update iframe height
    Create a html with Swagger UI for iframe
    """
    if page.file.name not in ("rest_api", "rest-api"):
        return output
    ...

Proposal

My proposal is:

  • Add an option (e.g, filter_filenames), which provides an optional list of filenames to match before proceding the processing.
  • For backward-compat, if this option is not provided the plugin continue with its current behavior.

What do you think? I can open a PR next week

pedro-psb added a commit to pedro-psb/mkdocs-swagger-ui-tag that referenced this issue May 13, 2024
@pedro-psb pedro-psb linked a pull request May 13, 2024 that will close this issue
pedro-psb added a commit to pedro-psb/mkdocs-swagger-ui-tag that referenced this issue May 16, 2024
@pedro-psb
Copy link
Author

Another similar approach is to mark specific markdown pages using the yaml frontmatter and add a global option to not process a page unless its marked.

# some markdown page frontmatter
---
swagger-ui:
  process-page: true
---

# mkdocs.yaml
plugins:
  mkdocs-swagger-ui:
    process_all: false  # default true for compatibility

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

Successfully merging a pull request may close this issue.

1 participant