_drupal_flush_css_js() keeps a history of the last 20 characters used in the query string. These are all different characters. The two latest added characters are appended to the query string.
The function guarantees that the two characters added to the query string change, each time _drupal_flush_css_js() is been called, and that no duplicate two-character strings appear within 20 calls. In more that 20 calls there is a chance of duplicates, though it is rather unlikely, because each new character is chosen at random.
This logic is hard to grasp, because it relies on both a recorded history and randomness. It is too complex IMO.
Other approaches include 1) just generate something “very” random in _drupal_flush_css_js() 2) use a timestamp, or 3) use a counter that is incremented in each call to _drupal_flush_css_js().
This patch implements 2). The timestamp is converted to base 36 for a more compact representation (6 characters). This could be made even more compact, e.g. by reducing the resolution (from 1 second).
Comment | File | Size | Author |
---|---|---|---|
#17 | drupal_flush_css_js-D6-2.patch | 2.4 KB | karschsp |
#5 | drupal_flush_css_js-D6-1.patch | 4.03 KB | c960657 |
drupal_flush_css_js-1.patch | 3.86 KB | c960657 | |
Comments
Comment #1
Dries CreditAttribution: Dries commentedI like this simplification, and I don't really see anything wrong with it.
Comment #2
pwolanin CreditAttribution: pwolanin commentedLooks reasonable - will add a few extra bytes per page. I suppose we could reduce that by dividing the timestamp by something like 100 at the risk that someone will do this operation twice in that time frame.
A simple counter is certainly another option - e.g.
so you have to clear the cache 1295 times before you hit 3 characters.
Comment #3
Dries CreditAttribution: Dries commentedCommitted the patch. I don't think the few extra bytes are a big deal, but we can consider Peter's suggestion in a follow-up patch.
Comment #5
c960657 CreditAttribution: c960657 commentedD6 backport.
Note that this issue is not only about reducing code complexity but also to avoid that URLs are being reused after 20 cache clears.
Comment #6
c960657 CreditAttribution: c960657 commentedComment #8
c960657 CreditAttribution: c960657 commented#5: drupal_flush_css_js-D6-1.patch queued for re-testing.
Comment #10
c960657 CreditAttribution: c960657 commentedThere must be some problem with the test bot. The patch applies cleanly here.
Comment #11
Gabriel R. CreditAttribution: Gabriel R. commentedSubscribe.
Comment #12
c960657 CreditAttribution: c960657 commented#5: drupal_flush_css_js-D6-1.patch queued for re-testing.
Comment #14
c960657 CreditAttribution: c960657 commentedEh, what? Over at http://qa.drupal.org/pifr/test/41738 everything is green.
Comment #15
karschsp CreditAttribution: karschsp commented#5: drupal_flush_css_js-D6-1.patch queued for re-testing.
Comment #17
karschsp CreditAttribution: karschsp commentedHere's an updated version of the patch in #5.