While working on making the breadcrumbs block cacheable, I noticed that they are also being rendered in template_preprocess_page()
.
So I put a strategic "early return" statement in template_preprocess_page()
. In a place where the DB should not be touched at all:
- At
/node
from 224 DB queries to 211. 13 DB queries saved! - At
/taxonomy/term/1
from 207 DB queries to 185. 22 DB queries saved!
AFAICT in D7, breadcrumb building was tied to menu tree building so it didn't trigger additional DB hits. But in D8, it's a stand-alone concept. So there are DB queries for it, even when you don't use them!
Plus, there is a lot of cruft in there that should never ever be used, like
$variables['base_path'] = base_path();
(Typically used for hardcoding links, which breaks when a site is multilingual, and for referring to images, which breaks when the site is integrated with a CDN.)
Comment | File | Size | Author |
---|---|---|---|
#1 | template_preprocess_page_db-DEMONSTRATE-2232577-1-do-not-test.patch | 498 bytes | Wim Leers |
Comments
Comment #1
Wim LeersComment #2
Wim LeersThis should probably be taken on by somebody who knows the theme system sufficiently well to know which things can be removed.
Note that the following issues should help in removing the majority of what's in
template_preprocess_page()
:Comment #3
star-szrComment #4
tim.plunkettWere you by chance tracking these with debug() calls and with dblog on? That would double the count...
On /taxonomy/term/{term}, I see
2 calls to
SELECT tag, invalidations, deletions FROM {cache_tags} WHERE tag IN (:tags)
3 calls to
SELECT cid, data, created, expire, serialized, tags, checksum_invalidations, checksum_deletions FROM {' . $this->connection->escapeTable($this->bin) . '} WHERE cid IN (:cids)
And 1 query for the taxonomy breadcrumb.
All of those will be moved when they turn into blocks, but they'll still be called.
So I'm not 100% sure this is worth worrying about.
Comment #5
dawehnerping @wim
Comment #6
alexpottComment #7
catchI think this is the right status? Or if it's critical and postponed on #2005546: Use branding block in place of page template branding variables (site name, slogan, site logo) then that issue needs to be bumped to critical.
Comment #8
Wim LeersConfirmed that this no longer causes 20 extra DB queries (instead, it causes zero extra queries!). The clean-up that we've done so far has severely diminished the problem indeed.
Comment #9
Wim LeersThis is actually being done at #507488: Convert page elements (local tasks, actions) into blocks.
Comment #10
Wim LeersNo trail of breadcrumbs (pun intended) in
template_preprocess_page()
anymore. Must've been removed elsewhere. Hurray!