-
-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Varun Patil <[email protected]>
- Loading branch information
Showing
12 changed files
with
299 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OCA\Memories\Db; | ||
|
||
use OCP\DB\QueryBuilder\IQueryBuilder; | ||
use OCP\Files\File; | ||
use OCP\IDBConnection; | ||
|
||
trait TimelineWriteFailures | ||
{ | ||
protected IDBConnection $connection; | ||
|
||
/** | ||
* Mark a file as failed indexing. | ||
* The file will not be re-indexed until it changes. | ||
* | ||
* @param File $file The file that failed indexing | ||
* @param string $reason The reason for the failure | ||
*/ | ||
public function markFailed(File $file, string $reason): void | ||
{ | ||
// Add file path to reason | ||
$reason .= " ({$file->getPath()})"; | ||
|
||
// Remove all previous failures for this file | ||
$this->connection->beginTransaction(); | ||
$this->clearFailures($file); | ||
|
||
// Add the failure to the database | ||
$query = $this->connection->getQueryBuilder(); | ||
$query->insert('memories_failures') | ||
->values([ | ||
'fileid' => $query->createNamedParameter($file->getId(), IQueryBuilder::PARAM_INT), | ||
'mtime' => $query->createNamedParameter($file->getMtime(), IQueryBuilder::PARAM_INT), | ||
'reason' => $query->createNamedParameter($reason, IQueryBuilder::PARAM_STR), | ||
]) | ||
->executeStatement() | ||
; | ||
$this->connection->commit(); | ||
} | ||
|
||
/** | ||
* Mark a file as successfully indexed. | ||
* The entry will be removed from the failures table. | ||
* | ||
* @param File $file The file that was successfully indexed | ||
*/ | ||
public function clearFailures(File $file): void | ||
{ | ||
$query = $this->connection->getQueryBuilder(); | ||
$query->delete('memories_failures') | ||
->where($query->expr()->eq('fileid', $query->createNamedParameter($file->getId(), IQueryBuilder::PARAM_INT))) | ||
->executeStatement() | ||
; | ||
} | ||
|
||
/** | ||
* Get the count of failed files. | ||
*/ | ||
public function countFailures(): int | ||
{ | ||
$query = $this->connection->getQueryBuilder(); | ||
$query->select($query->createFunction('COUNT(fileid)')) | ||
->from('memories_failures') | ||
; | ||
return (int) $query->executeQuery()->fetchOne(); | ||
} | ||
|
||
/** | ||
* Get the list of failures. | ||
*/ | ||
public function listFailures(): array | ||
{ | ||
return $this->connection->getQueryBuilder() | ||
->select('*') | ||
->from('memories_failures') | ||
->executeQuery() | ||
->fetchAll(); | ||
; | ||
} | ||
|
||
/** | ||
* Clear all failures from the database. | ||
*/ | ||
public function clearAllFailures(): void | ||
{ | ||
// Delete all entries and reset autoincrement counter | ||
$this->connection->executeStatement( | ||
$this->connection->getDatabasePlatform()->getTruncateTableSQL('*PREFIX*memories_failures', false)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* @copyright Copyright (c) 2023 Varun Patil <[email protected]> | ||
* @author Varun Patil <[email protected]> | ||
* @license GNU AGPL version 3 or any later version | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
namespace OCA\Memories\Migration; | ||
|
||
use OCP\DB\ISchemaWrapper; | ||
use OCP\DB\Types; | ||
use OCP\Migration\IOutput; | ||
use OCP\Migration\SimpleMigrationStep; | ||
|
||
class Version602003Date20240310203729 extends SimpleMigrationStep | ||
{ | ||
/** | ||
* @param Closure(): ISchemaWrapper $schemaClosure | ||
*/ | ||
public function preSchemaChange(IOutput $output, \Closure $schemaClosure, array $options): void {} | ||
|
||
/** | ||
* @param \Closure(): ISchemaWrapper $schemaClosure | ||
*/ | ||
public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options): ?ISchemaWrapper | ||
{ | ||
/** @var ISchemaWrapper $schema */ | ||
$schema = $schemaClosure(); | ||
|
||
if (!$schema->hasTable('memories_failures')) { | ||
$table = $schema->createTable('memories_failures'); | ||
$table->addColumn('id', 'integer', [ | ||
'autoincrement' => true, | ||
'notnull' => true, | ||
]); | ||
$table->addColumn('fileid', Types::BIGINT, [ | ||
'notnull' => true, | ||
'length' => 20, | ||
]); | ||
$table->addColumn('mtime', Types::BIGINT, [ | ||
'notnull' => true, | ||
'length' => 20, | ||
]); | ||
$table->addColumn('reason', 'text', [ | ||
'notnull' => false, | ||
]); | ||
|
||
$table->setPrimaryKey(['id']); | ||
$table->addIndex(['fileid', 'mtime'], 'memories_fail_fid_mt_idx'); | ||
} | ||
|
||
return $schema; | ||
} | ||
|
||
/** | ||
* @param Closure(): ISchemaWrapper $schemaClosure | ||
*/ | ||
public function postSchemaChange(IOutput $output, \Closure $schemaClosure, array $options): void {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.