Closed (fixed)
Project:
Less CSS Preprocessor
Version:
6.x-2.1
Component:
Code
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
4 May 2010 at 12:46 UTC
Updated:
29 Jul 2016 at 17:27 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
razunter commentedOld, unused files should be deleted too
Comment #2
sreynen commentedI think I disagree about deleting on cache clear. Can you explain your reasoning a little more?
Here's my thinking: LESS CSS files aren't really part of the cache. They come directly from the source .less files, and update whenever those files update. Clearing the cache does not change those source files, so it would just be wasted time to regenerate the exact same CSS file on the next page load.
Deleting unused files makes sense to me.
Comment #3
corey.aufang commentedDelete compiled .less files on cache clear doesn't make sense.
Once you're done modifying your source .less files, there won't be any changes in the compiled files, thus no reason to delete them.
If you're you don't like having the unused compiled files that are left over, I suggest deleting them once you're done with development. After that, there should be no need.
Comment #4
sreynen commentedIsn't this more "by design" than "fixed"?
Not a big deal, I'm just thinking about people looking at this issue in the future. Leaving the status as "fixed" seems to suggest the module now deletes files on cache clear. Unless I've misread this, nothing has actually changed.
Comment #5
razunter commentedWhen less file uses @import from other file, cache doesn't get updated when changing imported file
Comment #6
Raaagh commentedYep. This makes importing pretty much useless
Comment #7
sreynen commentedAs this was the stated reason for not fixing this, and #5 demonstrates there is a reason to delete them (to include updates to @import-ed files), I'm changing the status back to active. I'd be happy to work on a patch for this if there's some chance it would be used.
Comment #8
corey.aufang commentedValid point.
I will add a page with a button that will flush generated compiled LESS files.
Comment #9
amitaibuPatch adds a setting to enable debug mode, as it's important to allow a good flow using @import.
Patch also removes empty spaces.
Comment #10
xen commentedMay I instead suggest that _less_build does a regexp to find the files imported (recursively) and makes a note of them somewhere (not in cache, for obvious reasons) and use that to check the file time of all the originals against the generated file?
Would mean things would Just Work. CSS files would be regenerated when needed, without needless regeneration on each pageload.
Comment #11
corey.aufang commentedWhile #789410-10: Cache cleaning is an interesting idea, I believe that it is ultimately not needed.
Again, the only time that you need .less files compiled is during development. Checking file mod time for every file that are @import on every page load I think is excessive and a waste of CPU cycles.
In fact, checking mod time was originally put in to deal with modifications, and to make sure that they were detected, but since we need a way of making sure to include modifications from @import files, I'm thinking of removing mod time check.
Using the functionality in #789410-9: Cache cleaning in addition to a button that allows a manual refresh of the less files i think would be the best way to approach this situation.
Also when #789410-9: Cache cleaning is active, a message should be relayed to the screen (for people with the correct permissions) stating that the LESS cache is being regenerated on every page load, and this shouldnt be turned off for production.
Comment #12
xen commentedI beg to differ.
While I think it's a good idea to have a setting to turn of the checking of updated files in a production environment, and rely on clearing the processed files together with the regular cache clearing, I feel it's unsatisfactory to rebuild all CSS on every page load even in a development environment. Even though performance isn't the most important thing in a development environment, I don't think it should be ignored. Development is often done on the developers laptop, which may not be the fastest box on the block.
Comment #13
corey.aufang commentedI completely agree, which is why I also stated that there should be a button on the admin page that would cause a manual wipe + rebuild of the compiled LESS files.
Comment #14
xen commentedBut you're introducing another step the developer have to remember, ether pressing another button when changing less files, or switching on and off less debug mode.
The Devel module has a checkbox to rebuild the theme registry on each page load, but I'm never using it because it slows everything down, relying instead on
drush cc theme. If it had a 'rebuild registry when a theme hook changes' mode, I'd sure use that instead.Remembering the mtimes of the included files is a bit more work, but it would mean one less thing that the developer has to think about.
Oh, and it would be even nicer if the mtime statting only activated when the devel module is enabled.
Comment #15
sreynen commentedNot exactly. @corey.aufang's/@Amitaibu's solution is introducing another step developers can choose to use if they want, or developers can leave things working exactly as they do now. They would be introducing another step if there were already working code that does what you're describing, but there's not. So I suggest you write that code, as working code is the most compelling argument. And even if working code doesn't convince @corey.aufang, it could always work in a separate module.
Comment #16
xen commentedWell, they can't leave the things working like they do now, if corey.aufang removes the mtime check as he suggested in #11. If he does that, the only way to get CSS files rebuild is by some action of the developer, which is a step backwards from the current situation, where at least changes to the top file gets picked up.
Furthermore, removing the mtime check will mean that end-users will have to manually click the refresh button when updating LESS using modules.
Anyway, I suspected that someone would throw the 'show us the code' card, so here is a patch (pasted inline, as d.o keeps giving me validation errors). However, forking less.module isn't exactly an option.
The patch implements keeping track of the source files for a generated CSS file. It adds a developer mode at admin/settings/performance to activate it, and a verbose mode.
It also implements clearing the generated files on cache clear, which ensures that updating LESS using modules will regenerate their CSS. It does mean that files are generated more often than strictly necessary, but I've prioritised end-user convenience over maximum performance.
And I've fixed a bug, realpath returns false when the file doesn't exists (except on *BSDs in PHP < 5.3), which meant that on the pageload that generated the CSS file, it wouldn't replace the LESS file (only on subsequent pages).
Comment #17
corey.aufang commentedHere is my first pass for this issue.
I'm going to roll filemtime checks into the developer mode check at the top of _less_build(), at which point they will be removed from standard operation.
When developer mode is enabled it will check the filemtime's of the .less files and their @import children against the compiled file.
Comment #18
corey.aufang commentedFile didnt attach...
Comment #19
corey.aufang commentedAlso, I'm not going to use HOOK_flush_caches() because cache gets cleared on every cron run and we don't need to regenerate the compiled files every cron.
Comment #20
adamdicarlo commentedIf you modify an @import'ed LESS file, just touch the rest of your LESS files (the ones doing the @import'ing) to update their timestamps and thus have LESS detect that they need to be regenerated.
Comment #21
corey.aufang commentedI've committed the patch from #789410-18: Cache cleaning and a new dev should be available shortly.
I've left the regular filemtime checks in for now until we have full tree filemtime checks for dev mode.
Once we have an intelligent dev mode, I want to remove the filemtime checks from a regular run, as once your done with development, it should not be needed.
Comment #22
xen commentedQuestion: What happens when end users (ie. not developers, thus not running with flushing) updates a less using module with a change in an @imported file? Depending on how they update the module files, you cannot be sure that the timestamp on the @importing file changes too.
Comment #23
corey.aufang commentedGood point.
In this case we can use hook_flush_caches, but with code that will prevent rebuild on cron. So if the user manually flushes caches or goes through the update.php script, the files will be regenerated.
If a user doesn't run update.php when updating a module, then this would fall under expected behavior.
Comment #24
xen commentedWell, if manually flushing caches triggers a rebuild, you don't need the flush button on the settings page as people can just do a regular flush?
Comment #25
corey.aufang commentedThe reason that I mentioned using hook_flush_caches is because that is invoked at the end of update.php. So that would meet the need when a user that isn't a developer updates a module that uses LESS, with the condition that if they don't use update.php, then its their own fault.
The flush button on the settings pages gives the option to clear the less cache without having to clear all the other caches that are on their site.
Comment #26
corey.aufang commentedCommitted changes that include flushing compiled files on normal cache flush -cron.
Running update.php or flushing caches will cause a full flush of the compiled LESS files.
Also removed normal filemtime checks due to the above and currently don't see a need for recursive filemtime checking.
Comment #27
corey.aufang commentedCache cleaning is now available in the latest version (D6-2.5, D7-2.0).
Comment #29
jeffdukedotcom commentedNot sure if this is part of this issue...
When I 'Flush all caches' the less preporcessor creates a new compiled style.bunchoflettersnumbers.css as intended. It does NOT delete the old style.css. My sites require cache flushs' often and these files tend to build up. Are they supposed to be deleted during Flush all cache? They are not deleted on cron runs either. I see no need to keep all the old compiled .css files once a new one is created. Once a new one is created, it should delete the old ones. What am I doing wrong? How do I automatically get rid of the old compiled .css files once a new one is created?
Comment #30
corey.aufang commented@jeffdukedotcom please do not open old tickets, but open a new ticket referencing back to the old ticket in question.
Less cache clearing follows the same methods as core aggregated CSS cache clearing: drupal_clear_css_cache()
This by default deletes files that are older than 30 days.
You can adjust this threshold by overriding the 'drupal_stale_file_threshold' variable in your settings.php file.
For development you can set it to any number of seconds, but on a production site I wouldn't set it anything lower than 1 day's worth of seconds, 86400.