coleifer / micawber

a small library for extracting rich content from urls
http://micawber.readthedocs.org/
MIT License
635 stars 91 forks source link

bootstrap_embedly performance question #2

Closed inactivist closed 12 years ago

inactivist commented 12 years ago

Hi, I'm new to micawber, and I'm reading the docs. I have a question about bootstrap_embedly.

If I want to use embed.ly, is bootstrap_embedly required initialization every time? For example, if I call it in a django web app's initialization code, is it going to cause a delay at startup? Or does it cache results for future use?

From the docs:

>>> import micawber
>>> providers = micawber.bootstrap_embedly() # may take a second
>>> print micawber.parse_text('this is a test:\nhttp://www.youtube.com/watch?v=54XHDUOHuzU', providers)
this is a test:
<iframe width="640" height="360" src="http://www.youtube.com/embed/54XHDUOHuzU?fs=1&feature=oembed" frameborder="0" allowfullscreen></iframe>

A bit more detail in the docs regarding this issue would be appreciated.

coleifer commented 12 years ago

Hi, thanks for taking a look at my new project. If you're using django, it maintains the provider registry globally at module scope, so it is only loaded once when your application starts up. There will be a slight delay. If you are using django you can import the bootstrapped providers like this:


from micawber.contrib.mcdjango import providers
micawber.parse_text(..., providers)

You can of course write your own bootstrap_ function that does something similar to bootstrap_embedly and loads the rules from a file or the database. All you need to track is the provider's regex and the endpoint it is mapped to, which in embedly's case is always the same.

I've updated the docs to make this a bit more clear on this.

See https://github.com/coleifer/micawber/blob/master/micawber/contrib/mcdjango/__init__.py#L17

inactivist commented 12 years ago

Awesome, thanks for that info, it's exactly what I needed to know. Edit: I started code diving and saw that there was no caching... so I guess I was expecting most of your answer :D