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

Improve performance in getProviderEndpointForLinkUrl #140

Open
raae opened this issue Nov 10, 2020 · 1 comment
Open

Improve performance in getProviderEndpointForLinkUrl #140

raae opened this issue Nov 10, 2020 · 1 comment
Labels
enhancement New feature or request

Comments

@raae
Copy link
Member

raae commented Nov 10, 2020

The code in this function has three nested loops, so it's O(n3) (cubic time). We can probably improve upon this.

Originally posted by @nickytonline in #132 (comment)

@raae
Copy link
Member Author

raae commented Nov 10, 2020

We do have a step where the provider list is prepped for use, maybe change the structure of it so its easier to match url with schema.

Ie. going from this:

[
  {
    provider_name: "Twitter",
    provider_url: "http://www.twitter.com/",
    endpoints: [
      {
        schemes: [
          "https://twitter.com/*/status/*",
          "https://*.twitter.com/*/status/*"
        ],
        url: "https://publish.twitter.com/oembed"
      }
    ]
  }
]

to this:

[
  {
    scheme: "https://twitter.com/*/status/*",
    provider_name: "Twitter",
    provider_url: "http://www.twitter.com/",
    endpoint: "https://publish.twitter.com/oembed"
  },
  {
    scheme: "https://*.twitter.com/*/status/*",
    provider_name: "Twitter",
    provider_url: "http://www.twitter.com/",
    endpoint: "https://publish.twitter.com/oembed"
  }
]

Then we could loop through once per oEmbed link, and can break out of the loop as soon as we find it.

@raae raae added the enhancement New feature or request label Nov 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant