prismicio / SymfonyBundle

Inntegrates the http://prismic.io php-kit with the Symfony Framework
http://prismic.io
8 stars 11 forks source link

PrismicBundle brings site down if prismic.io unreachable #20

Closed fazy closed 8 years ago

fazy commented 9 years ago

Today my company's website was unable to connect to prismic.io, resulting in the whole Symfony 2 web application being unavailable with a 500 Server Error.

I think it was related to wider Internet connectivity issues and not an outage of Prismic, however it exposed a problem: the class Prismic\Bundle\PrismicBundle\EventListener\ContextListener appears to be initiating an API call to Prismic for every page load, even if we don't use Prismic on that page. In fact, we are only using Prismic for one small section of the site.

There are two things I would hope to improve here:

  1. Only call the Prismic API for pages that need it (can the call be deferred or lazy loaded)?
  2. If Prismic is unreachable, serve the last content from the cache

I'm not sure how to handle point 1, although I might try a try/catch around this line in the listener class mentioned above (and possibly the rest of that method):

$newRef = $this->context->getMasterRef();

Then, I could just log or ignore the error for pages that don't require Prismic. It's hacky, but would it work?

Regarding point 2, this might be difficult. I think the cache TTLs are usually very short, and if we make them long enough to survive a several hour outage, then we're going to be showing stale content after an update. So either cache invalidation is needed, or some kind of cache fallback (short TTL, try to request fresh content but serve from cache if failed).

How feasible is either approach? I guess having prismic.io call a callback after updating content isn't likely and might be problematic, so I'm thinking of using the "fallback" approach, perhaps by implementing Prismic\Cache\CacheInterface. However, I think I read somewhere that the cache keys change (i.e. if publishing a new page, it will have a differnete id), so is this workable?

Any thoughts would be appreciated.

erwan commented 9 years ago

Hi,

You're right, we should not fetch the Api object for pages that don't need it, not only for the problem you describe but also because it could have an impact on performances.

CHH commented 9 years ago

@fazy did you run the latest version? I’ve submitted a pull request, which removed the call to getMasterRef in the event listener.

erwan commented 8 years ago

pull request merged