Skip to content

Commit

Permalink
Laravel Octane optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
richan-fongdasen committed May 24, 2024
1 parent a038543 commit 54feaa6
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 10 deletions.
2 changes: 2 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
parameters:
treatPhpDocTypesAsCertain: false
ignoreErrors:
- identifier: missingType.iterableValue
- identifier: missingType.generics
- '#Variable method call on RichanFongdasen\\Turso\\TursoClient.#'
2 changes: 0 additions & 2 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,3 @@ parameters:
tmpDir: build/phpstan
checkOctaneCompatibility: true
checkModelProperties: true
checkMissingIterableValueType: false
checkGenericClassInNonGenericObjectType: false
8 changes: 2 additions & 6 deletions src/TursoClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,9 @@ public function __construct(array $config = [])

$this->queryLog = new Collection();

$this->enableQueryLog();
$this->disableQueryLog();
$this->resetHttpClientState();
}

public function __destruct()
{
$this->close();
$this->httpRequest();
}

public function close(): void
Expand Down
2 changes: 1 addition & 1 deletion src/TursoLaravelServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function register(): void
{
parent::register();

$this->app->scoped(TursoManager::class, function () {
$this->app->singleton(TursoManager::class, function () {
return new TursoManager(config('database.connections.turso', []));
});

Expand Down
45 changes: 45 additions & 0 deletions tests/Unit/TursoClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,48 @@

expect(Turso::getBaseUrl())->toBe('http://base-url-example.turso.io');
})->group('TursoClient', 'UnitTest');

test('it can close the existing http connection', function () {
fakeHttpRequest([
'baton' => 'baton-string-example',
'base_url' => 'http://base-url-example.turso.io',
'results' => [
[
'type' => 'ok',
'response' => [
'result' => [
'affected_row_count' => 1,
'last_insert_rowid' => '1',
'replication_index' => 0,
],
],
],
[
'type' => 'ok',
'response' => [
'result' => [
'affected_row_count' => 1,
'last_insert_rowid' => '1',
'replication_index' => 0,
],
],
],
],
]);

$statement = 'SELECT * FROM "users" WHERE "id" = ?';
$bindings = [
[
'type' => 'integer',
'value' => 1,
],
];

Turso::query($statement, $bindings);

expect(Turso::getBaton())->toBe('baton-string-example');

Turso::close();

expect(Turso::getBaton())->toBeNull();
})->group('TursoClient', 'UnitTest');
4 changes: 3 additions & 1 deletion turso-sync.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { createClient } from "@libsql/client";

const startTime = Date.now();

let databaseURL = process.argv.slice(2)[0];
const accessToken = process.argv.slice(2)[1];
const replicaPath = process.argv.slice(2)[2];
Expand All @@ -18,4 +20,4 @@ console.log('Syncing database to replica ' + replicaPath + ' from ' + databaseUR

await client.sync();

console.log('Sync completed.');
console.log('Sync completed in ' + (Date.now() - startTime) + 'ms.');

0 comments on commit 54feaa6

Please sign in to comment.