C.f. the issue title, advagg_enabled() is called 8 times on the sites we're working on, and this function has many problems:

  • It calls db_table_exists() sad but true story, this can be avoided using a variable set at install and update time
  • It does not statically caches its state, thus each time you call it, the whole business logic is run once again, including global overrides and db_table_exists() call

I did a simple patch, that sure needs some love, but it works gracefully on our site.

Is there any reason at all this method wouldn't statically cache its state?

Patch is coming!

Comments

pounard’s picture

Status: Active » Needs review
StatusFileSize
new1.87 KB

Here is the patch, reviews and comments are welcome. Hope it helps.

pounard’s picture

Actually this method is a very bad idea, you should just drop the check. Reason is that every person that would update the module would run update.php, that's a drupal core hard requirement. Modules don't have to do this kind of checks, if every module did it, we'd actually end up with a seriously messed up runtime.

You have to assume that any sane person would have run the update script before actually trying to hit the site, and that maintainance mode would have been set during the whole update.

The only thing to keep is the static cache to avoid running this method logic at every call, and remove the db_table_exists() check.

I'll post a new patch.

mikeytown2’s picture

Status: Needs review » Fixed
StatusFileSize
new2.5 KB

I've committed this patch. I think the only way to get rid of advagg_enabled would be to use hook_init. Still not sure what way would be better.

Thanks for helping me :)

pounard’s picture

I think that you should just drop the whole db_table_exists() check (replaced now by the variable_get) because I think that you have to assume users will always have an up to date database, so the check is useless. If you're more confortable with keeping it, why the heck not it won't hurt, but I think it's rather pointless and keep a useless complexity. In a few weeks or months you'll ask yourself why is this piece of code in here anyway?

Thanks for being reactive.

Status: Fixed » Closed (fixed)

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