Since the hook_cron inside honeypot checks that the css file is in it's place and not its contents those may get outdated when you change the element.

I think is not such an expensive operation to rebuild this css file on cron everytime.
I'll wait for feedback before rolling the patch that removes those two lines.

Right now what I'm doing is removing the file on a hook_update_N

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

rodrigoaguilera created an issue. See original summary.

geerlingguy’s picture

Doesn't it get rebuilt when you save the Honeypot admin form?

Otherwise, we could check the CSS file to make sure the class is the one that's specified in the variable (that way you could change the variable outside of the admin form itself, e.g. through settings.php, drush vset).

rodrigoaguilera’s picture

Exactly, I'm using it through strongarm + features

geerlingguy’s picture

Title: css file is not rebuilt when the element name changes » Rebuild CSS when the element name changes due to changing variable
Category: Bug report » Feature request

Changing to a feature request, and updating the title. I think this should be doable.

jastraat’s picture

I would also be interested in this. It's useful to be able to periodically update this variable with drush in all sites within a multi-site install.

rodrigoaguilera’s picture

I haven't thought about that, maybe making this variable an array and cycling through a list of names could add more effectiveness to the module but that should be on another issue.

geerlingguy’s picture

Version: 7.x-1.x-dev » 8.x-1.x-dev

Quick benchmark:

  • Running current cron operation (if file already exists) takes approximately 0.1ms
  • Recreating the file every time cron runs takes approximately 4ms

This is on an NFS mount, so times would be slightly faster with a local SSD, slightly slower depending on other factors... It's not the end of the world, but I don't take lightly an operation that adds a ton of extra time in performing a frequently-run operation...

That being said, we're talking < 100ms even in less-than-ideal situations like a slow GlusterFS mount, so I'm going to do a couple quick checks into other techniques, then if those don't pan out, I'll just pull out the check for the file existing in honeypot_cron().

geerlingguy’s picture

Version: 8.x-1.x-dev » 7.x-1.x-dev
Status: Active » Needs review
FileSize
3.04 KB

Going to do in 7.x first, as I was already playing around with the code there. Will forward port after new tests are green.

Also, this patch includes a new function honeypot_check_css(), which only takes 0.3-0.5ms to read the file and scan the single line for the element name (using strpos()). Just because I hate adding in unnecessary write operations to something that would potentially run up to once per minute on certain sites, I think it's worth adding a simple extra function to check the file before writing a new copy.

So basically, the goal of this ticket is resolved by the file only being written if either (a) it doesn't already exist (0.1ms lookup) or (b) it exists but doesn't contain the correct honeypot_element_name (0.5ms lookup). The 4+ms write operation only takes place if both a and b checks fail.

geerlingguy’s picture

Version: 7.x-1.x-dev » 8.x-1.x-dev
Status: Needs review » Patch (to be ported)
geerlingguy’s picture

Version: 8.x-1.x-dev » 7.x-1.x-dev
Status: Patch (to be ported) » Fixed

This is not an issue in 8.x, since the HTML is attached as a separate <style> tag in the head.

Status: Fixed » Closed (fixed)

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