I'm seeing this query come up a lot in devel:

0.462advagg_insert_bundle_db
SELECT checksum FROM advagg_files WHERE filename_md5 = '17d70dccb2b9f8a42f0557f3510e1c3d'

It sometimes appears twice for the same md5 hash, also there can be a lot of different individual queries for individual filenames on a page.

There's currently 200 records in this table on the site I'm looking at, it's a complex site so that ought to be close to the maximmum. So I'm wondering if when one checksum is needed, it wouldn't be worth just loading all of them and static caching them - would be a small amount of data to load and save quite a few queries on pages that need it.

Comments

mikeytown2’s picture

Issue summary: View changes

Looks like this query could be improved.

  foreach ($files as $order => $filename) {
    $filename_md5 = md5($filename);

    // Insert file into the advagg_files table if it doesn't exist.
    $checksum = db_result(db_query("SELECT checksum FROM {advagg_files} WHERE filename_md5 = '%s'", $filename_md5));
    if (empty($checksum)) {
      $checksum = advagg_checksum($filename);
      db_query("INSERT INTO {advagg_files} (filename, filename_md5, checksum, filetype, filesize) VALUES ('%s', '%s', '%s', '%s', %d)", $filename, $filename_md5, $checksum, $filetype, @filesize($filename));
    }

    // Create the entries in the advagg_bundles table.
    db_query("INSERT INTO {advagg_bundles} (bundle_md5, filename_md5, counter, porder, root, timestamp) VALUES ('%s', '%s', '%d', '%d', '%d', '%d')", $bundle_md5, $filename_md5, 0, $order, $root, time());
  }

Pull

    $checksum = db_result(db_query("SELECT checksum FROM {advagg_files} WHERE filename_md5 = '%s'", $filename_md5));

Out of the loop.

mikeytown2’s picture

Status: Active » Closed (won't fix)

Marking as won't fix as in I will not be writing this patch. I've laid out what needs to happen so creating a patch in this case should be easy to do. Re-open with a patch with a better query and I'll commit it.