Closed (fixed)
Project:
Project
Version:
5.x-1.x-dev
Component:
Releases
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
31 Jul 2007 at 01:59 UTC
Updated:
15 Aug 2007 at 21:37 UTC
Jump to comment: Most recent file
suggested by dww:
project_release_table() runs a set of expensive queries every time a table of releases is viewed. Since at the worse this table may change every few minutes when the packaging script runs, we should cache this result to help site (i.e. drupal.org) performance.
| Comment | File | Size | Author |
|---|---|---|---|
| #9 | table_cache_5.patch | 7.67 KB | dww |
| #8 | table_cache_4.patch | 6.99 KB | dww |
| #7 | table_cache_3.patch | 8.06 KB | pwolanin |
| #4 | table_cache_2.patch | 5.28 KB | pwolanin |
| #1 | table_cache_1.patch | 5.08 KB | pwolanin |
Comments
Comment #1
pwolanin commentedthis might work...
Comment #2
pwolanin commentedhmmm, but it can't be right. I'm guessing the packaging script runs for each and every project every ~5 min, so this code:
probably should not be in the packaging script, but rather in hook_cron or somewhere else. Is the packaging script invoked directly by cron? Where does the list of project nids come from then? I don't see a hook_cron in project module.
Comment #3
dwwThanks for taking an initial stab at this! To answer your questions and help clarify some things...
cache_clear_all(NULL, 'cache_project_release');Right, that shouldn't be in every invocation of package-release-nodes.php.
"Is the packaging script invoked directly by cron?"
Yes, by UNIX cron, completely outside of Drupal. It runs as a different user (with different permissions) than the httpd user. package-release-nodes.php is a CLI Drupal bootstrap script, not something to ever run from the web.
"Where does the list of project nids come from then?"
There's a magic command-line arg to only work on a single project, which is used for debugging and the occasional support request (e.g. changing the version info for a snapshot release and then rebuilding the tarball, etc). However, if you leave that off (which we do from cron), then the script itself does a big nasty query to find all the release nodes that need to be packaged for all projects -- see package_releases().
"I don't see a hook_cron in project module."
That's right. It's the UNIX crontab you're looking for, and you can't see it. ;) The script is invoked in "tag" mode every minutes (which only builds new official releases), and in "branch" mode every 12 hours (regenerates tarballs for any projects that have updated files).
So, I'd say:
A) package-release-nodes.php could keep track of each project for which it built a new tarball. When it's done, it could clear everything from {cache_project_release} for any cids that match the effected projects.
B) I wonder if {cache_project_release} isn't specific enough, and we should call it {cache_project_release_table} just to be sure?
C) You should only actually clear all when invoked for branches, not on every run.
Other things I noticed when skimming the patch:
D) Why doesn't the mysql case in the .install also check if the table already exists?
E) Shouldn't project_release_update_5000() test if the table already exists, too?
Comment #4
pwolanin commentedComment #5
pwolanin commentedopps - sorry about the unclosed tag above
Comment #6
dwwNot true. The existing install code just checks in a different way. On MySQL, you can do
CREATE TABLE IF NOT EXISTS. PgSQL doesn't have that, so you need the extra call todb_table_exists(). Please update the install (and upgrade) code to handle this. Thanks!Ahh, ok, that explains why you have "table" in the cache index string, then. ;) Makes sense to me.
Final point on cache clearing during the packaging script. You're almost there, but I think I'm not explaining what I have in mind very well. ;) Lemme try again...
- Packaging script always knows when it creates a new tarball for a given project.
- A new tarball is really the *only* reason to ever clear this cache info. If a project hasn't had any commits, the cached release table entry could be valid for weeks on end, not just 12 hours.
- I'm assuming that if a given project had multiple new tarballs generated (which is often the case -- if someone committed some changes, it's often to fix a bug and the patches get backported, etc) that it would be better to only try to clear that project's cache once, instead of re-clearing it for every tarball.
- Right now, package-release-nodes.php doesn't SELECT the project's nid in the query. We only know that if it was supplied on the command-line for a single project. However, it'd be trivial to change the SQL so we had the project nid, even when we're querying for all the release nodes that might need to be (re)built.
So, the kind of changes I have in mind would be a little bit more far-reaching in package-release-nodes.php, but I think the extra effort is worth it so that we don't clear the cache unnecessarily. I'll try to find you on IRC to coordinate further -- might be faster for me to just take your latest patch and crank out a new one with what I have in mind...
Thanks again for working on this!
-Derek
Comment #7
pwolanin commentedis this what you mean?
Comment #8
dwwAlmost. ;) More like this.
Comment #9
dwwThis was minorly broken in a few ways, mostly because I led pwolanin astray at various points... ;)
A) The cache id was wrong for clearing the cache for a specific project. We both left the 'table:' part off the front. ;)
B) We should really clear the cache for a project whenever a release node is added or updated, too, since that could effect various things.
C) We should also clear the cache if the project owner tweaks the settings on the "Releases" subtab of the edit page (e.g. to change the default major version for a given version of core).
New patch fixes all this. I tested the upgrade path, the fresh install, and a bunch of cases and everything looks great. I haven't yet tested the changes to the packaging script to clear the cache, so that still needs some testing...
Comment #10
dwwDid some more testing, and committed to HEAD. Just installed on d.o. Ran into an evil problem where, because d.o is now running memcached, the schema for cache_* tables has to be different. :( This caused an explosion of watchdog errors for a little while, until I undid the patch, manually altered the schema in the DB, and reapplied. Now, everything is running smoothly. I verified that project nodes look ok and that the {cache_project_release} table has some records now (1630 and counting). ;) Thanks!
Comment #11
(not verified) commented