Skip to content
This repository has been archived by the owner on May 8, 2018. It is now read-only.

Commit

Permalink
Use ?refresh for immediate updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruben Schmidmeister committed Jan 11, 2017
1 parent dcbfd54 commit d869121
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
6 changes: 4 additions & 2 deletions API/src/Commands/Posts/ArchivePostCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,14 @@ public function execute(string $postId): string
$archived = $this->postService->archivePost($postId);
$timestamp = (new StringDateTime($archived))->getTimestamp();

$this->elasticBackend->updateDocument('post', $postId, [
$document = [
'archived' => $timestamp,
'meta' => [
'delete_timestamp' => $timestamp + 3600 * 24 * 30
]
]);
];

$this->elasticBackend->updateDocument('post', $postId, $document, true);

return $archived;
}
Expand Down
6 changes: 4 additions & 2 deletions API/src/Commands/Posts/RestorePostCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,14 @@ public function execute(string $postId): void
{
$this->postService->restorePost($postId);

$this->elasticBackend->updateDocument('post', $postId, [
$document = [
'archived' => null,
'meta' => [
'delete_timestamp' => null
]
]);
];

$this->elasticBackend->updateDocument('post', $postId, $document, true);

$this->dataStoreWriter->queueTask(new \Timetabio\Library\Tasks\IndexPostTask($postId));
}
Expand Down
3 changes: 2 additions & 1 deletion Framework/src/Backends/ElasticBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,13 @@ public function indexChildDocument(string $type, string $id, string $parent, arr
]);
}

public function updateDocument(string $type, string $id, array $updates): array
public function updateDocument(string $type, string $id, array $updates, bool $refresh = false): array
{
return $this->client->update([
'index' => $this->index,
'type' => $type,
'id' => $id,
'refresh' => $refresh,
'body' => [
'doc' => $updates
]
Expand Down

0 comments on commit d869121

Please sign in to comment.