If you unprotect a form via the admin UI, that form is still in the cache. So if you call e.g. mollom_form_load() on it, it will still return data indicating that the form is being protected.

The attached patch clears the cache when the form is submitted.

Ideally I guess there would be a mollom_form_delete() function that took care of all this, plus a test, etc, but I don't have time to write that at the moment :)

Comments

dries’s picture

Also, because mollom_form_cache() caches in the database instead of a static variable, it would be more elegant to have an explicit mollom_{set|get|clear}_cache() functions instead of cramming it in one function. No reason to put everything in one function with a less intuitive API.

sun’s picture

@David: Thanks! I'll work out some tests. Adding a mollom_form_delete() is also a good idea.

@Dries: We can surely add a separate mollom_form_cache_reset(), but aside from that, a mollom_form_cache_set() would not make sense, since the cache data is auto-generated, so there is only a _get() and _clear(). So not sure I follow - to my knowledge, there is no situation in which we would want to clear the static cache or database cache only. While the database cache is required (as the code path to build the lists is relatively expensive), the additional static cache exists as performance optimization only; i.e., to not re-retrieve the identical data from cache during a single request.

But speaking of, I'm not happy with that manually crafted db/static cache pattern we introduced for D7, so I actually just happened to suggest #924616: Make database cache leverage static cache by default today -- which would allow us to get back to simple invocations of cache_get(), cache_set(), cache_clear_all() in almost all locations where a static cache wraps a cache_get() -- from which there are plenty.

dries’s picture

mollom_form_cache() does not use static caching. That said, if we don't have a _set(), it might be better to keep it in one function. Sorry for side-tracking us.

Looking at the code, I'm not sure the function name makes sense:

 * Returns a cached mapping of protected and delete confirmation form ids.
 * ... snip ...
 */
function mollom_form_cache($reset = FALSE) {

The fact that the function caches isn't really that important, and could probably be omitted from the function name. This is illustrated by the fact that the function's PHPdoc doesn't even mention the cache. See what I mean?

sun’s picture

mollom_form_cache() itself does not use a static, but mollom_form_alter() uses one for the returned database cache. That is, because mollom_form_cache() is invoked form other places, which don't necessarily need a static cache, as they only retrieve the data once. To keep it simple, we could change that -- though not contained in attached patch(es) yet.

The patch ending in "fail" only contains the tests, to make sure the tests are actually catching the bug.

dries’s picture

Version: 7.x-1.x-dev » 6.x-1.x-dev
Status: Needs review » Patch (to be ported)

Great -- I like the new approach in #4 and committed it to CVS HEAD. I guess we'll want to backport this to Drupal 6 so updating the status.

sun’s picture

Status: Patch (to be ported) » Needs review
StatusFileSize
new4.62 KB

Since there is no drupal_static() in D6, the patch looks slightly different. That said, it might make sense to change HEAD accordingly, after fixing the bug in D6.

As there is also no assertUrl() in D6, that is also different. (btw, I wrote the new assertUrl() in D7 based on Mollom's tests ;)) I hope this patch passes.

sun’s picture

StatusFileSize
new5.31 KB
dries’s picture

Status: Needs review » Fixed

Committed to DRUPAL-6. Thanks.

sun’s picture

Version: 6.x-1.x-dev » 7.x-1.x-dev
Status: Fixed » Needs review
StatusFileSize
new1.7 KB

Feel free to hate me for this, but I'd really like to keep branches in sync. :)

sun’s picture

Status: Needs review » Fixed

Committed to HEAD.

Status: Fixed » Closed (fixed)

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

  • Commit 3779ce2 on master, fai6, 8.x-2.x, fbajs, actions by Dries:
    - Patch #924612 by sun, David_Rothstein: cache is not cleared when a...
  • Commit 8ac683e on master, fai6, 8.x-2.x, fbajs, actions by sun:
    #924612 by sun: Synced static mollom_form_cache() with D6.
    
    

  • Commit 3779ce2 on master, fai6, 8.x-2.x, fbajs, actions by Dries:
    - Patch #924612 by sun, David_Rothstein: cache is not cleared when a...
  • Commit 8ac683e on master, fai6, 8.x-2.x, fbajs, actions by sun:
    #924612 by sun: Synced static mollom_form_cache() with D6.