Skip to content

Commit

Permalink
fail graceful if MetaService can't read content
Browse files Browse the repository at this point in the history
  • Loading branch information
korelstar committed Aug 25, 2020
1 parent fc3719c commit afa1192
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions lib/Service/MetaService.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,11 @@
*/
class MetaService {
private $metaMapper;
private $noteUtil;

public function __construct(MetaMapper $metaMapper) {
public function __construct(MetaMapper $metaMapper, NoteUtil $noteUtil) {
$this->metaMapper = $metaMapper;
$this->noteUtil = $noteUtil;
}

public function deleteByNote(int $id) : void {
Expand Down Expand Up @@ -130,7 +132,7 @@ private function createMeta(string $userId, Note $note) : Meta {
}

private function updateIfNeeded(Meta &$meta, Note $note, bool $forceUpdate) : bool {
$generateContentEtag = $forceUpdate;
$generateContentEtag = $forceUpdate || !$meta->getContentEtag();
$fileEtag = $note->getFileEtag();
// a changed File-ETag is an indicator for changed content
if ($fileEtag !== $meta->getFileEtag()) {
Expand All @@ -155,9 +157,14 @@ private function updateIfNeeded(Meta &$meta, Note $note, bool $forceUpdate) : bo

// warning: this is expensive
private function generateContentEtag(Note $note) : string {
return Util::retryIfLocked(function () use ($note) {
return md5($note->getContent());
}, 3);
try {
return Util::retryIfLocked(function () use ($note) {
return md5($note->getContent());
}, 3);
} catch (\Throwable $t) {
$this->noteUtil->logException($t);
return '';
}
}

// this is not expensive, since we use the content ETag instead of the content itself
Expand Down

0 comments on commit afa1192

Please sign in to comment.