Skip to content

Commit

Permalink
Official release of Ravendb
Browse files Browse the repository at this point in the history
  • Loading branch information
Geolim4 committed Jan 13, 2024
1 parent 4dfc27b commit a9e41ad
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 8 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
## 9.2.0
##### 10 january 2024
##### 13 january 2024
- __Driver Core__
- Driver is maintained by @Geolim4
- `Ravendb` is a new extension separated from the main Phpfastcache repository.
47 changes: 40 additions & 7 deletions lib/Phpfastcache/Extensions/Drivers/Ravendb/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,25 @@
use Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException;
use Phpfastcache\Exceptions\PhpfastcacheUnsupportedMethodException;
use RavenDB\Documents\DocumentStore;
use RavenDB\Documents\Operations\CollectionStatistics;
use RavenDB\Documents\Operations\DeleteByQueryOperation;
use RavenDB\Documents\Operations\DetailedDatabaseStatistics;
use RavenDB\Documents\Operations\GetCollectionStatisticsOperation;
use RavenDB\Documents\Operations\GetDetailedStatisticsOperation;
use RavenDB\Documents\Queries\IndexQuery;
use RavenDB\Documents\Session\DocumentSession;
use RavenDB\Documents\Session\QueryStatistics;
use RavenDB\Exceptions\RavenException;
use RavenDB\Http\ServerNode;
use RavenDB\ServerWide\Operations\BuildNumber;
use RavenDB\ServerWide\Operations\Configuration\GetDatabaseSettingsOperation;
use RavenDB\ServerWide\Operations\GetBuildNumberOperation;
use RavenDB\Type\Duration;

/**
* Class Driver
* @property DocumentSession $instance Instance of driver service
* @method Config getConfig()
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class Driver implements AggregatablePoolInterface
{
Expand Down Expand Up @@ -85,10 +91,15 @@ protected function driverConnect(): bool
if ($authOptions) {
$this->documentStorage->setAuthOptions($authOptions);
}
$this->documentStorage->getConventions()->setFindCollectionName(fn () => $this->getConfig()->getCollectionName());
$this->documentStorage->getConventions()->setFindCollectionName(fn () => $this->getCollectionName());
$this->documentStorage->getConventions()->setFindIdentityProperty(static fn () => 'key');
$this->documentStorage->getConventions()->setRequestTimeout(Duration::ofSeconds(1));
$this->documentStorage->initialize();
$this->documentStorage->getRequestExecutor()->setDefaultTimeout(Duration::ofSeconds(1));
$this->instance = $this->documentStorage->openSession();// @phpstan-ignore-line
if ($this->documentStorage->maintenance()->send(new GetDatabaseSettingsOperation($this->getDatabaseName())) === null) {
throw new RavenException('Unable to fetch databases metadata.');
}
} catch (RavenException $e) {
throw new PhpfastcacheDriverConnectException('Unable to connect to Raven server: ' . $e->getMessage());
}
Expand Down Expand Up @@ -234,7 +245,7 @@ protected function driverDeleteMultiple(array $keys): bool
protected function driverClear(): bool
{
$this->documentStorage->operations()->send(
new DeleteByQueryOperation(new IndexQuery(sprintf('from %s', $this->getConfig()->getCollectionName())))
new DeleteByQueryOperation(new IndexQuery(sprintf('from %s', $this->getCollectionName())))
);

$this->instance->clear();
Expand All @@ -249,12 +260,16 @@ public function getStats(): DriverStatistic
$nodes = $this->instance->getRequestExecutor()->getTopology()->getNodes();
/** @var BuildNumber|null $buildNumber */
$buildNumber = $this->documentStorage->maintenance()->server()->send(new GetBuildNumberOperation());
/** @var CollectionStatistics $collectionStats */
$collectionStats = $this->documentStorage->maintenance()->send(new GetCollectionStatisticsOperation());
/** @var DetailedDatabaseStatistics $databaseStats */
$databaseStats = $this->documentStorage->maintenance()->send(new GetDetailedStatisticsOperation());

return (new DriverStatistic())
->setRawData(['build' => $buildNumber, 'nodes' => $nodes])
$driverStats = (new DriverStatistic())
->setRawData(compact('nodes', 'buildNumber', 'collectionStats', 'databaseStats'))
->setInfo(
sprintf(
'Ravendb server v%s (%s), client v%s with %s node%s configured: %s',
'Ravendb server v%s (%s), client v%s with %s node%s configured: %s. Database/Collection: "%s"/"%s".',
$buildNumber?->getFullVersion() ?? 'Unknown version',
$buildNumber?->getCommitHash() ?? '********',
InstalledVersions::getPrettyVersion('ravendb/ravendb-php-client'),
Expand All @@ -263,9 +278,19 @@ public function getStats(): DriverStatistic
implode(', ', array_map(
fn(ServerNode $node) => 'Node #' . $node->getClusterTag() . ' (' . $node->getServerRole()->getValue() . ') @ ' . $node->getUrl()->getValue(),
iterator_to_array($nodes)
))
)),
$this->getDatabaseName(),
$this->getCollectionName(),
)
);

if (method_exists($driverStats, 'setCount')) {
$driverStats->setCount(
$collectionStats->getCollections()[$this->getCollectionName()] ?? $collectionStats->getCountOfDocuments()
);
}

return $driverStats;
}

/**
Expand All @@ -275,4 +300,12 @@ protected function getDatabaseName(): string
{
return $this->getConfig()->getDatabaseName() ?: static::RAVENDB_DEFAULT_DB_NAME;
}

/**
* @return string
*/
protected function getCollectionName(): string
{
return $this->getConfig()->getCollectionName() ?: static::RAVENDB_DEFAULT_COLLECTION_NAME;
}
}

0 comments on commit a9e41ad

Please sign in to comment.