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

Cache source packages when reference/revision is available #367

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

adduc
Copy link

@adduc adduc commented Apr 26, 2017

Fixes #366

For projects that use specific revisions for packages (e.g. if a bug fix has not made it to a tagged release yet), the PHP language server would reparse the package's files every time the server started, even if the package had not changed. This change introduces caching support for packages that are checked out from source, by using the revision as part of the cache key.

@codecov
Copy link

codecov bot commented Apr 26, 2017

Codecov Report

Merging #367 into master will increase coverage by 2.61%.
The diff coverage is 37.5%.

@@             Coverage Diff              @@
##             master     #367      +/-   ##
============================================
+ Coverage     84.33%   86.95%   +2.61%     
- Complexity      834      835       +1     
============================================
  Files            59       59              
  Lines          1724     1732       +8     
============================================
+ Hits           1454     1506      +52     
+ Misses          270      226      -44
Impacted Files Coverage Δ Complexity Δ
src/Indexer.php 91.25% <37.5%> (+28.23%) 19 <0> (+1) ⬆️
src/Index/ProjectIndex.php 100% <0%> (ø) 4% <0%> (ø) ⬇️
src/LanguageServer.php 95.18% <0%> (+2.4%) 20% <0%> (ø) ⬇️
src/Index/Index.php 80.39% <0%> (+11.76%) 21% <0%> (ø) ⬇️
src/Index/DependenciesIndex.php 53.33% <0%> (+40%) 6% <0%> (ø) ⬇️
src/Cache/FileSystemCache.php 70% <0%> (+50%) 8% <0%> (ø) ⬇️

@adduc
Copy link
Author

adduc commented Apr 26, 2017

Regarding testing for this change, I'm still wrapping my head around the code. I think it can be accomplished by including a composer.json and composer.lock within fixtures to mock a faux install. I'm going to look into this further.

src/Indexer.php Outdated
$packageVersion = ltrim($package->version, 'v');
// If package is anchored to a version
if ($package->name === $packageName && strpos($packageVersion, 'dev') === false) {
Copy link
Owner

Choose a reason for hiding this comment

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

package name is checked in both conditions

src/Indexer.php Outdated
if ($package->name === $packageName && strpos($packageVersion, 'dev') === false) {
$packageKey = $packageName . ':' . $packageVersion;
$cacheKey = self::CACHE_VERSION . ':' . $packageKey;
// Check cache
$index = yield $this->cache->get($cacheKey);
break;

// If package is checked out
} elseif ($package->name === $packageName && isset($package->source->reference)) {
Copy link
Owner

Choose a reason for hiding this comment

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

space between else if

@felixfbecker
Copy link
Owner

LGTM overall.
Testing with a fake composer.json and composer.lock sounds like a good approach. Ideally this would be a unit test for the Indexer that asserts a stubbed Cache is called

@adduc
Copy link
Author

adduc commented Apr 30, 2017

I've made changes based off your feedback, and modified tests for the two current package caching strategies.

I think this is ready for another review.

@felixfbecker
Copy link
Owner

Could you do the tests as a unit test for the Indexer?

@adduc adduc force-pushed the cache-revisions branch from 54831bc to ee5a7d7 Compare April 30, 2017 16:58
@adduc
Copy link
Author

adduc commented Apr 30, 2017

I'd be willing to give it a shot.

@umpirsky
Copy link

umpirsky commented Jul 6, 2017

Any updates on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cache Key is not set when dependent repository targets a specific commit
3 participants