diff options
| author | winter | 2025-05-08 23:46:20 +0100 |
|---|---|---|
| committer | winter | 2025-05-08 23:46:20 +0100 |
| commit | 09b3847233adbdfbd7496d81d2a2f93fae0d0ee4 (patch) | |
| tree | d114086b014b7713d83e178e45e26a46c9daf19b | |
| parent | 478cf68228b0157da9446354a993804ddac65d51 (diff) | |
automatically generate link previews for new incoming notes after some delay
| -rw-r--r-- | Digitigrade/Job/GenerateLinkPreviews.php | 28 | ||||
| -rw-r--r-- | Digitigrade/Job/ProcessIncomingPush.php | 7 |
2 files changed, 32 insertions, 3 deletions
diff --git a/Digitigrade/Job/GenerateLinkPreviews.php b/Digitigrade/Job/GenerateLinkPreviews.php new file mode 100644 index 0000000..acaccbb --- /dev/null +++ b/Digitigrade/Job/GenerateLinkPreviews.php @@ -0,0 +1,28 @@ +<?php +namespace Digitigrade\Job; + +use Digitigrade\Job; +use Digitigrade\JobQueue; +use Digitigrade\Logger; +use Digitigrade\Model\Note; + +class GenerateLinkPreviews extends Job { + public int $noteId; + + public function __construct(Note $note) { + $this->noteId = $note->id; + $this->remainingTries = 4; + } + + public function run() { + $note = Note::find($this->noteId); + Logger::getInstance()->info('Generating link previews for note: ' . $note->uri); + $note->generateLinkPreviews(); + $note->save(); + } + + public function submit() { + // submit it after a random delay to avoid deluging the websites being previewed + JobQueue::getInstance()->submitDelayed($this, random_int(0, 60 * 15 /* 15 minutes */)); + } +}
\ No newline at end of file diff --git a/Digitigrade/Job/ProcessIncomingPush.php b/Digitigrade/Job/ProcessIncomingPush.php index 384949b..55f4fc0 100644 --- a/Digitigrade/Job/ProcessIncomingPush.php +++ b/Digitigrade/Job/ProcessIncomingPush.php @@ -37,9 +37,10 @@ class ProcessIncomingPush extends Job { $log->info('importing note with uri ' . $this->object->self); $alreadyExisted = Note::countWhere('uri = ?', [$this->object->self]) > 0; $note = Note::importFromReceivedObject($this->object); - if (!$alreadyExisted) { - $note?->processTimelineAdditions(); - $note?->processNotifications(); + if (!$alreadyExisted && isset($note)) { + $note->processTimelineAdditions(); + $note->processNotifications(); + (new GenerateLinkPreviews($note))->submit(); } break; case 'interaction': |
