Skip to content

Commit ee59bbe

Browse files
authored
Merge pull request #2309 from nextcloud/feat/clear-previews-last-preview
feat(ClearPreviews): Clear last_preview column in addition to cache
2 parents 269f38e + 4f7ba0c commit ee59bbe

2 files changed

Lines changed: 18 additions & 7 deletions

File tree

lib/Command/ClearPreviews.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,18 @@
88

99
namespace OCA\Bookmarks\Command;
1010

11+
use OCA\Bookmarks\Db\BookmarkMapper;
1112
use OCA\Bookmarks\Service\FileCache;
1213
use Symfony\Component\Console\Command\Command;
1314
use Symfony\Component\Console\Input\InputInterface;
1415
use Symfony\Component\Console\Output\OutputInterface;
1516

1617
class ClearPreviews extends Command {
17-
/**
18-
* @var FileCache
19-
*/
20-
private $fileCache;
21-
22-
public function __construct(FileCache $fileCache) {
18+
public function __construct(
19+
private FileCache $fileCache,
20+
private BookmarkMapper $bookmarkMapper,
21+
) {
2322
parent::__construct();
24-
$this->fileCache = $fileCache;
2523
}
2624

2725
/**
@@ -45,6 +43,7 @@ protected function configure() {
4543
protected function execute(InputInterface $input, OutputInterface $output): int {
4644
try {
4745
$this->fileCache->clear();
46+
$this->bookmarkMapper->clearLastPreviews();
4847
} catch (\Exception $ex) {
4948
$output->writeln('<error>Failed to clear previews</error>');
5049
$output->writeln($ex->getMessage());

lib/Db/BookmarkMapper.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -724,12 +724,24 @@ public function findPendingPreviews(int $limit, int $stalePeriod): array {
724724
return $this->findEntities($qb);
725725
}
726726

727+
/**
728+
* @return void
729+
* @throws Exception
730+
*/
731+
public function clearLastPreviews(): void {
732+
$qb = $this->db->getQueryBuilder();
733+
$qb->update('bookmarks');
734+
$qb->set('last_preview', $qb->createNamedParameter(0));
735+
$qb->executeStatement();
736+
}
737+
727738
/**
728739
* @psalm-param Bookmark $entity
729740
* @param Entity $entity
730741
*
731742
* @return Bookmark
732743
* @psalm-return Bookmark
744+
* @throws Exception
733745
*/
734746
public function delete(Entity $entity): Bookmark {
735747
$this->eventDispatcher->dispatch(

0 commit comments

Comments
 (0)