Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added assets versioning #12591

Closed
wants to merge 1 commit into from
Closed

Conversation

Jurigag
Copy link
Contributor

@Jurigag Jurigag commented Feb 1, 2017

Hello!

In raising this pull request, I confirm the following (please check boxes):

  • I have read and understood the Contributing Guidelines?
  • I have checked that another pull request for this purpose does not exist.
  • I wrote some tests for this PR.

Small description of change: This change is adding assets versioning setting it either in resource or collection, resource version overrides collection version with option for automatic assets versioning using filemtime.

Thanks

@Jurigag Jurigag force-pushed the 3.1.x-assets-versioning branch 3 times, most recently from 356cfc7 to 8bf8fb3 Compare February 1, 2017 17:37
@Jurigag
Copy link
Contributor Author

Jurigag commented Feb 1, 2017

Also i think Manager::output needs in future some recator cuz it looks like it have duplicated code.

@Jurigag Jurigag force-pushed the 3.1.x-assets-versioning branch from 8bf8fb3 to 357d09e Compare February 1, 2017 17:51
}
let prefixedPath = prefixedPath . "?ver=" . version;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dislike such pasta code

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh so let prefixedPath .= "?ver=" . version ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideologically the version must be a string or null. Not boolean or yet another type.

Copy link
Contributor Author

@Jurigag Jurigag Feb 1, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean i wanted true/false to make it automatic versioning - so version is file modification time as you can see in this code. Don't really see a point in adding seperated method for version from filemtime or something like this.

Copy link
Contributor

@sergeyklay sergeyklay Feb 1, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So do you prefer to introduce an entity that means anything instead of 2 specialized methods

Copy link
Contributor Author

@Jurigag Jurigag Feb 1, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well yea, cuz this will require to https://github.com/phalcon/cphalcon/pull/12591/files#diff-f14ebcff6721de771f55f77e6f962321R96 have another argument too. I mean maybe your solution is better, i can change it, just felt it will be better to have just one method/argument added which can be used for both stuff.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Green-Cat @SidRoberts @Izopi4a @wolftankk @akatasonov what you think above another method?

Copy link
Member

@Izopi4a Izopi4a Feb 2, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i find this PR very useful. maybe if this pasta is ugly, we can like in volt services..


$di->set('assets', function(){
  $cls = new Assets(); 
  $cls->setAppendString("?ver=".$config->assetsVersion);
  
  return $cls;
}

but as i said, versioning to assets its very important for me.

both cases, i dont think it should matter that much, its nothing un debuggable, its not super hard to understand and we can always change it if some person explain it sux

Copy link
Contributor Author

@Jurigag Jurigag Feb 2, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like append string. What with auto versioning? What with other version for certain resource etc? I can add other argument and method but it will mean that there will be additional argument - and as you can see in current code it's not necessary really. Shouldn't we keep things simple, stupid instead of adding something which is not needed?

}
let prefixedPath = prefixedPath . "?ver=" . version;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same here

@david-duncan
Copy link

I try to refrain from commenting if it's not constructive but this really doesn't belong in the framework.

@Jurigag
Copy link
Contributor Author

Jurigag commented Feb 2, 2017

Why it doesn't belong in the framework? There is assets manager in framework so why not add versioning to it which is pretty need feature i think(like we wan't people to refresh their js/css)?

@sergeyklay
Copy link
Contributor

sergeyklay commented Feb 2, 2017

I prefer a more flexible approach. For example Version Strategy (incremental, direct, etc). A separated entity with delegated responsibility.

@Jurigag
Copy link
Contributor Author

Jurigag commented Feb 2, 2017

How this is not flexible? For resource versioning it depends hardly on Resource itself, cuz in resource is uri generated for certain resources, as well uri for joined resources is generated in collection.

@Jurigag Jurigag force-pushed the 3.1.x-assets-versioning branch 2 times, most recently from b3576ee to 5428fdb Compare February 2, 2017 12:09
@sergeyklay
Copy link
Contributor

What we can have:

  • Incremental strategy
  • Explicit strategy
  • md5/crc32 (from content)
  • Timestamp strategy

Do you really want to incapsulate all this in one optional parameter and introduce a pasta factory for it?

@Jurigag
Copy link
Contributor Author

Jurigag commented Feb 2, 2017

md5/crc32 from content is really bad way for performance. Some example for incremental/explict strategy, what you mean by them? It can't obviously increment itself.... You can either provide version by hand like 1.0.0 setting version or to tell framework to generate it from timestamp. How it supposed to increment version?

Right now incremental, explict and timestamp is implemented with this code so i don't see a problem.

@sergeyklay
Copy link
Contributor

The problem is not that something isn't done. I mean design and single responsibility.

@sergeyklay
Copy link
Contributor

sergeyklay commented Feb 2, 2017

Do you really like such design?

if version != null {
    if version {
        if version === true {
            // ...
        }
    }
}

@Jurigag Jurigag force-pushed the 3.1.x-assets-versioning branch from 5428fdb to 57d502e Compare February 2, 2017 14:01
@Jurigag
Copy link
Contributor Author

Jurigag commented Feb 2, 2017

So you like more something like:

$assets->addJs(PATH_DATA.'assets/script1.js', true, false, null, '1.0.0'); // 1.0.0 version
$assets->addJs(PATH_DATA.'assets/script1.js', true, false, null, null, true); // version from timestamp
$assets->addJs(PATH_DATA.'assets/script1.js', true, false, null, '1.0.0', true); // and here we should have what and why?

?

@sergeyklay
Copy link
Contributor

I will keep this PR open for a some time to allow other contributors a chance to speak up, and to take a fresh look at it later.

@Jurigag Jurigag force-pushed the 3.1.x-assets-versioning branch 2 times, most recently from 70647a0 to d2b7d2b Compare February 2, 2017 15:04
@Jurigag
Copy link
Contributor Author

Jurigag commented Feb 2, 2017

Failing tests seems unrelated.

@Jurigag Jurigag closed this Feb 2, 2017
@Jurigag Jurigag reopened this Feb 2, 2017
@sergeyklay sergeyklay added this to the 3.2.0 milestone Mar 8, 2017
@Jurigag Jurigag changed the base branch from 3.1.x to 3.2.x March 23, 2017 11:06
@Jurigag Jurigag force-pushed the 3.1.x-assets-versioning branch from d2b7d2b to deb303e Compare March 24, 2017 14:17
@Jurigag Jurigag changed the base branch from 3.2.x to 3.4.x May 28, 2018 15:28
@Jurigag Jurigag force-pushed the 3.1.x-assets-versioning branch from ba01336 to 3364d85 Compare May 28, 2018 16:44
@Jurigag Jurigag changed the base branch from 3.4.x to 4.0.x May 28, 2018 16:44
@Jurigag
Copy link
Contributor Author

Jurigag commented May 28, 2018

Rebased onto 4.0.x, let me see if tests pass because i don't remember.

@Jurigag Jurigag closed this May 28, 2018
@Jurigag Jurigag reopened this May 28, 2018
@sergeyklay
Copy link
Contributor

@Jurigag There is few issues with 4.0.x branch. Let me fix them and update the branch

@sergeyklay sergeyklay closed this May 30, 2018
@sergeyklay sergeyklay reopened this May 30, 2018
@sergeyklay sergeyklay modified the milestones: 3.4.x, 4.0.0 May 30, 2018
@Jurigag
Copy link
Contributor Author

Jurigag commented May 30, 2018

I guess i need to update tests. I will do it in a few days.

@sergeyklay
Copy link
Contributor

sergeyklay commented May 30, 2018

@Jurigag Assets auto versioning with collection doesn't work correctly. Take a look at
Phalcon\Test\Unit\Assets\ManagerTest::testAssetsAutoVersioningCollection:

- Expected
+ Actual
@@ @@
'<script type="text/javascript" src="/home/travis/build/phalcon/cphalcon/tests/_data/assets/script1.js?ver=1.0.0"></script>\n
-<script type="text/javascript" src="/home/travis/build/phalcon/cphalcon/tests/_data/assets/script2.js?ver=1527660806"></script>\n
+<script type="text/javascript" src="/home/travis/build/phalcon/cphalcon/tests/_data/assets/script2.js"></script>\n
#1  /home/travis/build/phalcon/cphalcon/tests/unit/Assets/ManagerTest.php:714
#2  Phalcon\Test\Unit\Assets\ManagerTest->Phalcon\Test\Unit\Assets\{closure}
#3  /home/travis/build/phalcon/cphalcon/tests/unit/Assets/ManagerTest.php:715
#4  Phalcon\Test\Unit\Assets\ManagerTest->testAssetsAutoVersioningCollection

@sergeyklay
Copy link
Contributor

sergeyklay commented May 30, 2018

Also please use CHANGELOG-4.x and do not change CHANGELOG.md

* Should version be determined from file modification time
* @var bool
*/
protected _autoVersion = false { set };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I propose to not introduce anymore _prefixed variables. Lets use autoVersion instead of _autoVersion.

/**
* Phalcon\Assets\Resource constructor
*/
public function __construct(string type, string path, boolean local = true, boolean filter = true, array attributes = [])
public function __construct(string type, string path, boolean local = true, boolean filter = true, attributes = null, var version = null, var autoVersion = null)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Jurigag Do we really need to change attributes type? The Phalcon v4 will have a lot of BC incompatible changes. Could you please try to sort out how to avoid yet another

let version = this->_version;

if this->_autoVersion && this->_local {
let modificationTime = filemtime(this->getRealSourcePath());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the filemtime is I/O function, which will be called for each request. right?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: The results of this function are cached. See clearstatcache() for more details.
https://secure.php.net/filemtime#refsect1-function.filemtime-notes

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, right.

@niden niden added new feature request Planned Feature or New Feature Request and removed New Feature Request labels Mar 11, 2019
@niden niden mentioned this pull request May 10, 2019
4 tasks
niden pushed a commit that referenced this pull request May 12, 2019
niden added a commit that referenced this pull request May 12, 2019
niden added a commit that referenced this pull request May 12, 2019
niden added a commit that referenced this pull request May 12, 2019
@niden
Copy link
Member

niden commented May 12, 2019

Resolved in #14056

@niden niden closed this May 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new feature request Planned Feature or New Feature Request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants