Skip to content

Commit

Permalink
Merge pull request #10 from koalatiapp/fix-empty-changeset
Browse files Browse the repository at this point in the history
fix: prevent unnecessary api calls for updates with empty changeset
  • Loading branch information
EmilePerron authored Mar 4, 2023
2 parents 7552529 + f9d026b commit 88d6b54
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/Api/Module/CmsEndpoints.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,14 @@ public function createCollectionItem(string|Collection $collectionId, Collection
*/
public function updateCollectionItem(string|Collection $collectionId, CollectionItem $item, bool $publishImmediately): CollectionItem
{
$changeset = $item->getChangeset();

if (! $changeset) {
return $item;
}

$payload = [
'fields' => $item->getChangeset(),
'fields' => $changeset,
];
$url = "/collections/{$collectionId}/items/{$item}";

Expand Down
4 changes: 4 additions & 0 deletions src/Api/Module/MembershipEndpoints.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ public function updateUser(string|Site $siteId, User $user): User
$payload = $user->getChangeset();
unset($payload['email'], $payload['password']);

if (! $payload) {
return $user;
}

$response = $this->request('PATCH', "/sites/{$siteId}/users/{$user}", $payload);

if (! $response['valid']) {
Expand Down

0 comments on commit 88d6b54

Please sign in to comment.