Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/Db/CoreRequestBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Doctrine\DBAL\Query\QueryBuilder;
use OCA\FullTextSearch\Model\Index;
use OCA\FullTextSearch\Service\ConfigService;
use OCP\DB\Exception;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IDBConnection;
use OCP\IL10N;
Expand All @@ -33,7 +34,7 @@ public function __construct(
) {
}

protected function reconnect(ConnectionException $ex): void {
protected function reconnect(Exception $ex): void {
if ($this->lastReconnect > time() - 2) {
// in case we just reconnected a second ago
throw $ex;
Expand Down
130 changes: 82 additions & 48 deletions lib/Db/IndexesRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@
namespace OCA\FullTextSearch\Db;


use OCA\FullTextSearch\Exceptions\DatabaseException;
use Doctrine\DBAL\Exception\ConnectionException;
use OCA\FullTextSearch\Exceptions\IndexDoesNotExistException;
use OCA\FullTextSearch\Model\Index;
use OCP\DB\Exception;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\FullTextSearch\Model\IIndex;
use OCP\IDBConnection;


/**
Expand Down Expand Up @@ -48,10 +46,13 @@ public function create(Index $index): bool {
->setValue('indexed', $qb->createNamedParameter($index->getLastIndex()));

try {
$qb->execute();
} catch (ConnectionException $e) {
$this->reconnect($e);
return $this->create($index);
$qb->executeStatement();
} catch (Exception $e) {
if ($e->getReason() === Exception::REASON_CONNECTION_LOST) {
$this->reconnect($e);
return $this->create($index);
}
throw $e;
}

return true;
Expand All @@ -77,7 +78,7 @@ public function resetError(Index $index): bool {
$this->limitToProviderId($qb, $index->getProviderId());
$this->limitToDocumentId($qb, $index->getDocumentId());
$this->limitToCollection($qb, $index->getCollection());
$qb->execute();
$qb->executeStatement();

return true;
}
Expand All @@ -91,7 +92,7 @@ public function resetAllErrors() {
$qb->set('message', $qb->createNamedParameter(json_encode([])));
$qb->set('err', $qb->createNamedParameter(0));

$qb->execute();
$qb->executeStatement();
}


Expand All @@ -104,10 +105,13 @@ public function getErrorIndexes(): array {

$indexes = [];
try {
$cursor = $qb->execute();
} catch (ConnectionException $e) {
$this->reconnect($e);
return $this->getErrorIndexes();
$cursor = $qb->executeQuery();
} catch (Exception $e) {
if ($e->getReason() === Exception::REASON_CONNECTION_LOST) {
$this->reconnect($e);
return $this->getErrorIndexes();
}
throw $e;
}

while ($data = $cursor->fetch()) {
Expand Down Expand Up @@ -149,9 +153,13 @@ public function update(Index $index, bool $statusOnly = false): void {

try {
$qb->executeStatement();
} catch (ConnectionException $e) {
$this->reconnect($e);
$this->update($index, $statusOnly);
} catch (Exception $e) {
if ($e->getReason() === Exception::REASON_CONNECTION_LOST) {
$this->reconnect($e);
$this->update($index, $statusOnly);
return;
}
throw $e;
}
}

Expand All @@ -170,10 +178,14 @@ public function updateStatus(string $collection, string $providerId, string $doc
$this->limitToCollection($qb, $collection);

try {
$qb->execute();
} catch (ConnectionException $e) {
$this->reconnect($e);
$this->updateStatus($collection, $providerId, $documentId, $status);
$qb->executeStatement();
} catch (Exception $e) {
if ($e->getReason() === Exception::REASON_CONNECTION_LOST) {
$this->reconnect($e);
$this->updateStatus($collection, $providerId, $documentId, $status);
return;
}
throw $e;
}
}

Expand All @@ -194,10 +206,14 @@ public function updateStatuses(string $collection, string $providerId, array $in
$this->limitToCollection($qb, $collection);

try {
$qb->execute();
} catch (ConnectionException $e) {
$this->reconnect($e);
$this->updateStatuses($collection, $providerId, $indexes, $status);
$qb->executeStatement();
} catch (Exception $e) {
if ($e->getReason() === Exception::REASON_CONNECTION_LOST) {
$this->reconnect($e);
$this->updateStatuses($collection, $providerId, $indexes, $status);
return;
}
throw $e;
}
}

Expand All @@ -214,7 +230,7 @@ public function resetCollection(string $collection) {
$qb->set('status', $qb->createNamedParameter(IIndex::INDEX_FULL));
$this->limitToCollection($qb, $collection);

$qb->execute();
$qb->executeStatement();
}

/**
Expand All @@ -228,9 +244,12 @@ public function deleteIndex(IIndex $index) {

try {
$qb->executeStatement();
} catch (ConnectionException $e) {
$this->reconnect($e);
return $this->deleteIndex($index);
} catch (Exception $e) {
if ($e->getReason() === Exception::REASON_CONNECTION_LOST) {
$this->reconnect($e);
return $this->deleteIndex($index);
}
throw $e;
}
}

Expand All @@ -253,7 +272,7 @@ public function deleteFromProviderId(string $providerId, string $collection = ''
$qb = $this->getIndexesDeleteSql();
$this->limitToProviderId($qb, $providerId);

$qb->execute();
$qb->executeStatement();
}


Expand Down Expand Up @@ -288,10 +307,13 @@ public function getIndex(string $providerId, string $documentId, string $collect
$this->limitToCollection($qb, $collection);

try {
$cursor = $qb->execute();
} catch (ConnectionException $e) {
$this->reconnect($e);
return $this->getIndex($providerId, $documentId, $collection);
$cursor = $qb->executeQuery();
} catch (Exception $e) {
if ($e->getReason() === Exception::REASON_CONNECTION_LOST) {
$this->reconnect($e);
return $this->getIndex($providerId, $documentId, $collection);
}
throw $e;
}

$data = $cursor->fetch();
Expand Down Expand Up @@ -320,10 +342,13 @@ public function getIndexes(string $providerId, string $documentId): array {

$indexes = [];
try {
$cursor = $qb->execute();
} catch (ConnectionException $e) {
$this->reconnect($e);
return $this->getIndexes($providerId, $documentId);
$cursor = $qb->executeQuery();
} catch (Exception $e) {
if ($e->getReason() === Exception::REASON_CONNECTION_LOST) {
$this->reconnect($e);
return $this->getIndexes($providerId, $documentId);
}
throw $e;
}

while ($data = $cursor->fetch()) {
Expand Down Expand Up @@ -356,10 +381,13 @@ public function getQueuedIndexes(string $collection = '', bool $all = false, int

$indexes = [];
try {
$cursor = $qb->execute();
} catch (ConnectionException $e) {
$this->reconnect($e);
return $this->getQueuedIndexes($collection, $all, $length);
$cursor = $qb->executeQuery();
} catch (Exception $e) {
if ($e->getReason() === Exception::REASON_CONNECTION_LOST) {
$this->reconnect($e);
return $this->getQueuedIndexes($collection, $all, $length);
}
throw $e;
}

while ($data = $cursor->fetch()) {
Expand All @@ -384,10 +412,13 @@ public function getIndexesFromProvider(string $providerId): array {

$indexes = [];
try {
$cursor = $qb->execute();
} catch (ConnectionException $e) {
$this->reconnect($e);
return $this->getIndexesFromProvider($providerId);
$cursor = $qb->executeQuery();
} catch (Exception $e) {
if ($e->getReason() === Exception::REASON_CONNECTION_LOST) {
$this->reconnect($e);
return $this->getIndexesFromProvider($providerId);
}
throw $e;
}

while ($data = $cursor->fetch()) {
Expand Down Expand Up @@ -417,9 +448,12 @@ public function getCollections(bool $local = true): array {

try {
$cursor = $qb->executeQuery();
} catch (ConnectionException $e) {
$this->reconnect($e);
return $this->getCollections(true);
} catch (Exception $e) {
if ($e->getReason() === Exception::REASON_CONNECTION_LOST) {
$this->reconnect($e);
return $this->getCollections(true);
}
throw $e;
}

while ($data = $cursor->fetch()) {
Expand Down
46 changes: 28 additions & 18 deletions lib/Db/TickRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@
namespace OCA\FullTextSearch\Db;

use Exception;
use Doctrine\DBAL\Exception\ConnectionException;
use OCA\FullTextSearch\Exceptions\TickDoesNotExistException;
use OCA\FullTextSearch\Model\Tick;
use OCP\Server;

/**
* Class TickRequest
Expand All @@ -38,10 +36,13 @@ public function create(Tick $tick): int {
->setValue('status', $qb->createNamedParameter($tick->getStatus()));

try {
$qb->execute();
} catch (ConnectionException $e) {
$this->reconnect($e);
return $this->create($tick);
$qb->executeStatement();
} catch (\OCP\DB\Exception $e) {
if ($e->getReason() === \OCP\DB\Exception::REASON_CONNECTION_LOST) {
$this->reconnect($e);
return $this->create($tick);
}
throw $e;
}

return $qb->getLastInsertId();
Expand Down Expand Up @@ -71,10 +72,13 @@ public function update(Tick $tick): bool {
$this->limitToId($qb, $tick->getId());

try {
$qb->execute();
} catch (ConnectionException $e) {
$this->reconnect($e);
return $this->update($tick);
$qb->executeStatement();
} catch (\OCP\DB\Exception $e) {
if ($e->getReason() === \OCP\DB\Exception::REASON_CONNECTION_LOST) {
$this->reconnect($e);
return $this->update($tick);
}
throw $e;
}

return true;
Expand All @@ -93,10 +97,13 @@ public function getTickById(int $id): Tick {
$this->limitToId($qb, $id);

try {
$cursor = $qb->execute();
} catch (ConnectionException $e) {
$this->reconnect($e);
return $this->getTickById($id);
$cursor = $qb->executeQuery();
} catch (\OCP\DB\Exception $e) {
if ($e->getReason() === \OCP\DB\Exception::REASON_CONNECTION_LOST) {
$this->reconnect($e);
return $this->getTickById($id);
}
throw $e;
}

$data = $cursor->fetch();
Expand All @@ -123,10 +130,13 @@ public function getTicksByStatus(string $status): array {
$this->limitToStatus($qb, $status);

try {
$cursor = $qb->execute();
} catch (ConnectionException $e) {
$this->reconnect($e);
return $this->getTicksByStatus($status);
$cursor = $qb->executeQuery();
} catch (\OCP\DB\Exception $e) {
if ($e->getReason() === \OCP\DB\Exception::REASON_CONNECTION_LOST) {
$this->reconnect($e);
return $this->getTicksByStatus($status);
}
throw $e;
}

while ($data = $cursor->fetch()) {
Expand Down