parent
a611169e7d
commit
86c3c260a1
|
@ -5,26 +5,12 @@ declare(strict_types=1);
|
||||||
namespace OCA\Memories\Db;
|
namespace OCA\Memories\Db;
|
||||||
|
|
||||||
use OCP\DB\QueryBuilder\IQueryBuilder;
|
use OCP\DB\QueryBuilder\IQueryBuilder;
|
||||||
use OCP\Files\File;
|
|
||||||
use OCP\IDBConnection;
|
use OCP\IDBConnection;
|
||||||
|
|
||||||
trait TimelineWriteOrphans
|
trait TimelineWriteOrphans
|
||||||
{
|
{
|
||||||
protected IDBConnection $connection;
|
protected IDBConnection $connection;
|
||||||
|
|
||||||
/**
|
|
||||||
* Mark a file as not orphaned.
|
|
||||||
*/
|
|
||||||
public function unorphan(File &$file)
|
|
||||||
{
|
|
||||||
$query = $this->connection->getQueryBuilder();
|
|
||||||
$query->update('memories')
|
|
||||||
->set('orphan', $query->createNamedParameter(false, IQueryBuilder::PARAM_BOOL))
|
|
||||||
->where($query->expr()->eq('fileid', $query->createNamedParameter($file->getId(), IQueryBuilder::PARAM_INT)))
|
|
||||||
;
|
|
||||||
$query->executeStatement();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mark all files in the table as orphaned.
|
* Mark all files in the table as orphaned.
|
||||||
*
|
*
|
||||||
|
@ -43,19 +29,4 @@ trait TimelineWriteOrphans
|
||||||
|
|
||||||
return $do('memories') + $do('memories_livephoto');
|
return $do('memories') + $do('memories_livephoto');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Remove all entries that are orphans.
|
|
||||||
*
|
|
||||||
* @return int Number of rows affected
|
|
||||||
*/
|
|
||||||
public function removeOrphans(): int
|
|
||||||
{
|
|
||||||
$query = $this->connection->getQueryBuilder();
|
|
||||||
$query->delete('memories')
|
|
||||||
->where($query->expr()->eq('orphan', $query->createNamedParameter(true, IQueryBuilder::PARAM_BOOL)))
|
|
||||||
;
|
|
||||||
|
|
||||||
return $query->executeStatement();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -144,12 +144,12 @@ class Index
|
||||||
// Filter out files that are already indexed
|
// Filter out files that are already indexed
|
||||||
$addFilter = function (string $table, string $alias) use (&$query) {
|
$addFilter = function (string $table, string $alias) use (&$query) {
|
||||||
$query->leftJoin('f', $table, $alias, $query->expr()->andX(
|
$query->leftJoin('f', $table, $alias, $query->expr()->andX(
|
||||||
$query->expr()->eq('f.fileid', "$alias.fileid"),
|
$query->expr()->eq('f.fileid', "{$alias}.fileid"),
|
||||||
$query->expr()->eq('f.mtime', "$alias.mtime"),
|
$query->expr()->eq('f.mtime', "{$alias}.mtime"),
|
||||||
$query->expr()->eq("$alias.orphan", $query->createNamedParameter(false, IQueryBuilder::PARAM_BOOL))
|
$query->expr()->eq("{$alias}.orphan", $query->createNamedParameter(false, IQueryBuilder::PARAM_BOOL))
|
||||||
));
|
));
|
||||||
|
|
||||||
$query->andWhere($query->expr()->isNull("$alias.fileid"));
|
$query->andWhere($query->expr()->isNull("{$alias}.fileid"));
|
||||||
};
|
};
|
||||||
$addFilter('memories', 'm');
|
$addFilter('memories', 'm');
|
||||||
$addFilter('memories_livephoto', 'lp');
|
$addFilter('memories_livephoto', 'lp');
|
||||||
|
|
Loading…
Reference in New Issue