Skip to content

Commit

Permalink
Remove caching for now
Browse files Browse the repository at this point in the history
  • Loading branch information
felixfbecker committed Oct 26, 2016
1 parent 867196b commit d7bed7f
Showing 1 changed file with 0 additions and 59 deletions.
59 changes: 0 additions & 59 deletions src/LanguageServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ public function initialize(int $processId, ClientCapabilities $capabilities, str

// start building project index
if ($rootPath !== null) {
$this->restoreCache();
$this->indexProject();
}

Expand Down Expand Up @@ -135,9 +134,6 @@ public function initialize(int $processId, ClientCapabilities $capabilities, str
*/
public function shutdown()
{
if ($this->rootPath !== null) {
$this->saveCache();
}
}

/**
Expand Down Expand Up @@ -181,69 +177,14 @@ private function indexProject()
}
}

if ($fileNum % 1000 === 0) {
$this->saveCache();
}

Loop\setTimeout($processFile, 0);
} else {
$duration = (int)(microtime(true) - $startTime);
$mem = (int)(memory_get_usage(true) / (1024 * 1024));
$this->client->window->logMessage(MessageType::INFO, "All PHP files parsed in $duration seconds. $mem MiB allocated.");
$this->saveCache();
}
};

Loop\setTimeout($processFile, 0);
}

/**
* Restores the definition and reference index from the .phpls cache directory, if available
*
* @return void
*/
public function restoreCache()
{
$cacheDir = $this->rootPath . '/.phpls';
if (is_dir($cacheDir)) {
if (file_exists($cacheDir . '/symbols')) {
$symbols = unserialize(file_get_contents($cacheDir . '/symbols'));
$count = count($symbols);
$this->project->setSymbols($symbols);
$this->client->window->logMessage(MessageType::INFO, "Restoring $count symbols");
}
if (file_exists($cacheDir . '/references')) {
$references = unserialize(file_get_contents($cacheDir . '/references'));
$count = array_sum(array_map('count', $references));
$this->project->setReferenceUris($references);
$this->client->window->logMessage(MessageType::INFO, "Restoring $count references");
}
} else {
$this->client->window->logMessage(MessageType::INFO, 'No cache found');
}
}

/**
* Saves the definition and reference index to the .phpls cache directory
*
* @return void
*/
public function saveCache()
{
// Cache definitions, references
$cacheDir = $this->rootPath . '/.phpls';
if (!is_dir($cacheDir)) {
mkdir($cacheDir);
}

$symbols = $this->project->getSymbols();
$count = count($symbols);
$this->client->window->logMessage(MessageType::INFO, "Saving $count symbols to cache");
file_put_contents($cacheDir . "/symbols", serialize($symbols));

$references = $this->project->getReferenceUris();
$count = array_sum(array_map('count', $references));
$this->client->window->logMessage(MessageType::INFO, "Saving $count references to cache");
file_put_contents($cacheDir . "/references", serialize($references));
}
}

0 comments on commit d7bed7f

Please sign in to comment.