kriswallsmith/assetic — pull request #427 by mpdude (2013-05-23 23:19:17+00:00)
Title: Problems with the "deep mtime" approach

We've been trying to get the new "deep mtime" feature running for a simple SCSS file that ```@imports``` another file. I've got the impression that there's still a subtle bug, although I still don't understand 100% why it happens or how to fix it.

I get into LazyAssetManager::getLastModified() with an $asset that is an AssetCollection as follows.

$asset: an AssetCollection
filters: [ ScssFilter, CssRewriteFilter ]
assets: [ $fileAsset ]
$fileAsset: a FileAsset (SCSS file)

(hope you get the idea)

Now around line 228, LazyAssetManager ```clone```s this Collection, clears the filter, adds (in the first iteration) the ScssFilter again and calls ```$clone->load()``` (line 233).

This brings us to AssetCollection::load, which (around line 131 there) loops

foreach ($this as $asset) ...

At that moment the AssetCollectionIterator kicks in (in AssetCollection::getIterator) and somehow (must be related to the "clones" passed, don't get it) we end up with an $asset that contains the original two filters (Scss and CssRewrite).

This asset's getContent() does not anymore contain the original ```@import``` statements so the filter's getChildren() method (called in LazyAssetManager line 241) cannot find the "deep" assets anymore.

I was inclined to fix this with a special treatment for AssetCollections in the LazyAssetManager, however, that's probably wrong as the AssetCollection should handle it internally for this use case.

___Additional question 1___

A variation of this case where I am unsure how things would behave is if the ```$fileAsset``` from above would in turn hold a filter. If so, where would the "extraction" (incrementally applying all filters to the raw asset, scanning each intermediate result) happen for this ```$fileAsset```?

___Additional question 2___

As I get it, LazyAssetManager::getLastModified() incrementally applies all filters to a given asset and uses the "next last" filter to extract the "deep" assets (as new Assets).

Because that happens (in each iteration) on a clone, I am wondering if the filters at the beginning of the chain are executed repeatedly?

Also, getLastModified() needs to be called to determine if the compiled/processed set of assets is still fresh. It would obviously be pointless to (partially) process the assets to look at the intermediate result to determine the "deep" dependencies in every request. So how does the information about the deep dependencies get cached?