When using this, we can take advantage of the Drupal caching mechanism. Local testing makes the request about 4 times faster as well.

Haven't figured out how/or when exactly to clear it, but it's a good step forward though.

CommentFileSizeAuthor
#10 cache-simplesitemap.patch5.82 KBswentel
#2 2670676-2.patch922 bytesswentel
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

swentel created an issue. See original summary.

swentel’s picture

Status: Active » Needs review
FileSize
922 bytes

And the patch

  • gbyte.co committed 336700a on 8.x-1.x
    Issue #2670676 by swentel: Use CacheableResponse instead of Response
    
gbyte’s picture

Status: Needs review » Fixed

Just pushed it, as it didn't introduce functionality problems. If anything, it should speed up the sitemap index, as this is the only thing generated on the fly, however I haven't noticed any speed increse.

There should be no performance improvements if index is turned off. Feel free to submit patches if you feel this implementation is not yet optimal.

swentel’s picture

Cool thanks!
Generation itself is fast, and now when caching is enabled, Drupal doesn't need to fully bootstrap when there's a cached version, it can even live in varnish now respecting the TTL, cool!

I'll have a look in integrating with the purge module so that it can invalidated on demand, will post that in a different issue.

  • gbyte.co committed 336700a on 8.x-2.x
    Issue #2670676 by swentel: Use CacheableResponse instead of Response
    
gbyte’s picture

Status: Fixed » Needs work

I had to go back to Response because the cached output sometimes persists after sitemap regeneration.
@swentel Do you happen to know the best way to invalidate the CachedResponse? This invalidation should happen shortly before sitemap generation.

swentel’s picture

I'll have a look at this during Drupalcamp London this weekend :)

gbyte’s picture

Sounds like lots of fun, I'd join you if I could. Feel free to rip this module apart.

D8 needs some attention as well. E.g the batch api is a mess (hence its messy implementation in 2.x).

Anyway have fun!

swentel’s picture

Status: Needs work » Needs review
FileSize
5.82 KB

New patch, which also includes a test to actually prove that it works :)

I also removed the drupal_set_message() call from the generate_sitemap() method as it doesn't really belong there.

  • gbyte.co committed 473d867 on 8.x-1.x authored by swentel
    Issue #2670676 by swentel: Use CacheableResponse instead of Response
    
gbyte’s picture

Status: Needs review » Needs work

Great stuff!

Pity you didn't write it against 2.x, I ported it to 2.x as well as I do not intend to maintain 1.x for much longer.

Initial tests are successful in both branches, except for a small issue in 1.x where you go to sitemap.xml right after installing the module and an error occurs:
LogicException: The controller result claims to be providing relevant cache metadata, but leaked metadata was detected. Please ensure you are not rendering content too early.

This happens only when visiting sitemap.xml having never generated the sitemap. This issue is not present in 2.x. Shell I keep the issue open for you? ;)

swentel’s picture

I had problems getting things configured in the UI in the 2.x branch (got exceptions with plugins, but didn't really look into why), so I switched back to 1.x. Yes leave the issue open so I can trace it down, because I remember having the exception at least once myself too, but couldn't reproduce it anymore afterwards.

swentel’s picture

Otoh, like you say, 2.x branch is probably the best path forward, especially because of the module namespace :)
Let me think about it for a couple of days, I'll let you know.

gbyte’s picture

Exceptions with plugins? Strange, haven't had any problems with 2.x. It's just important to uninstall and remove the files of 1.x before installing 2.x. If you find you still have a problem, please open a new issue.

The exception in 1.x is reproducible by installing the module and going to sitemap.xml without generating the sitemap.

The only thing that probably won't be working in 2.x is your test, as the batch will start new threads and the code in testSimplesitemap() will not wait for the sitemap's generation.

Thanks for your input.

gbyte’s picture

Version: 8.x-1.x-dev » 8.x-2.x-dev
Status: Needs work » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

tedfordgif’s picture

This doesn't seem to result in the request being cacheable. I think a different approach is needed, as seen in Feed::buildResponse. I'm testing with Drupal 8.2.x. If this rings true in your testing, I'll open a new issue, unless you want to re-open this one.

Edit: Disregard, sorry for the noise.