Skip to content

Commit afcf1d4

Browse files
committed
do not run query if delta contains no data on save
1 parent 03220b0 commit afcf1d4

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

src/Entity.php

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -123,17 +123,24 @@ public function save(bool $validate = true, bool $delta = true): self
123123
$data = $delta ? \array_diff_assoc($this->data ?? [], $this->__data ?? []) : $this->data;
124124

125125
if ($this->getId()) {
126-
$this->medoo->update($this->getTable(), $data, ['id' => $this->getId()]);
126+
// If delta is empty, do not run query at all
127+
if ($data) {
128+
$this->medoo->update($this->getTable(), $data, ['id' => $this->getId()]);
129+
}
127130
} else {
128131
$this->medoo->insert($this->getTable(), $data);
129132
$this->setId($this->medoo->id());
130133
}
131-
$this->sentry->breadcrumbs->record([
132-
'message' => 'Entity '.$this->__getEntityName().'::save()',
133-
'data' => ['query' => $this->medoo->last()],
134-
'category' => 'Database',
135-
'level' => 'info',
136-
]);
134+
135+
// Record breadcrumb only if we had query
136+
if ($data || !$this->getId()) {
137+
$this->sentry->breadcrumbs->record([
138+
'message' => 'Entity '.$this->__getEntityName().'::save()',
139+
'data' => ['query' => $this->medoo->last()],
140+
'category' => 'Database',
141+
'level' => 'info',
142+
]);
143+
}
137144

138145
return $this;
139146
}

0 commit comments

Comments
 (0)