mirror of
https://github.com/appwrite/appwrite
synced 2026-05-22 16:38:32 +00:00
feat: improve migration speed
This commit is contained in:
parent
81ae56a676
commit
27be739d5e
1 changed files with 15 additions and 35 deletions
|
|
@ -124,21 +124,7 @@ abstract class Migration
|
|||
$old = $document->getArrayCopy();
|
||||
$new = call_user_func($callback, $document);
|
||||
|
||||
foreach ($document as &$attr) {
|
||||
if ($attr instanceof Document) {
|
||||
$attr = call_user_func($callback, $attr);
|
||||
}
|
||||
|
||||
if (\is_array($attr)) {
|
||||
foreach ($attr as &$child) {
|
||||
if ($child instanceof Document) {
|
||||
$child = call_user_func($callback, $child);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$this->check_diff_multi($new->getArrayCopy(), $old)) {
|
||||
if (!$this->hasDifference($new->getArrayCopy(), $old)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -170,32 +156,26 @@ abstract class Migration
|
|||
*
|
||||
* @param array $array1
|
||||
* @param array $array2
|
||||
* @return array
|
||||
* @return bool
|
||||
*/
|
||||
public function check_diff_multi(array $array1, array $array2): array
|
||||
public function hasDifference(array $array1, array $array2): bool
|
||||
{
|
||||
$result = array();
|
||||
|
||||
foreach ($array1 as $key => $val) {
|
||||
if (is_array($val) && isset($array2[$key])) {
|
||||
$tmp = $this->check_diff_multi($val, $array2[$key]);
|
||||
if ($tmp) {
|
||||
$result[$key] = $tmp;
|
||||
foreach ($array1 as $key => $value) {
|
||||
if (is_array($value)) {
|
||||
if (!isset($array2[$key]) || !is_array($array2[$key])) {
|
||||
return true;
|
||||
} else {
|
||||
$new_diff = $this->hasDifference($value, $array2[$key]);
|
||||
if ($new_diff) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} elseif (!isset($array2[$key])) {
|
||||
$result[$key] = null;
|
||||
} elseif ($val !== $array2[$key]) {
|
||||
$result[$key] = $array2[$key];
|
||||
}
|
||||
|
||||
if (isset($array2[$key])) {
|
||||
unset($array2[$key]);
|
||||
} elseif (!array_key_exists($key, $array2) || $array2[$key] !== $value) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
$result = array_merge($result, $array2);
|
||||
|
||||
return $result;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in a new issue