Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
2 changes: 1 addition & 1 deletion lib/Service/Note.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function getContent() : string {
$content = '';
}
if (!is_string($content)) {
throw new \Exception('Can\'t read file content.');
throw new \Exception('Can\'t read file content for '.$this->file->getPath());
}
if (!mb_check_encoding($content, 'UTF-8')) {
$content = mb_convert_encoding($content, 'UTF-8');
Expand Down