Skip to content

Commit

Permalink
NEW Use custom list for eagerloaded relations (#10869)
Browse files Browse the repository at this point in the history
  • Loading branch information
GuySartorelli committed Aug 3, 2023
1 parent f591ac9 commit ae49e13
Show file tree
Hide file tree
Showing 15 changed files with 3,669 additions and 247 deletions.
17 changes: 17 additions & 0 deletions src/ORM/ArrayLib.php
Expand Up @@ -274,4 +274,21 @@ public static function iterateVolatile(array &$list)
}
}
}

/**
* Similar to shuffle, but retains the existing association between the keys and the values.
* Shuffles the array in place.
*/
public static function shuffleAssociative(array &$array): void
{
$shuffledArray = [];
$keys = array_keys($array);
shuffle($keys);

foreach ($keys as $key) {
$shuffledArray[$key] = $array[$key];
}

$array = $shuffledArray;
}
}
19 changes: 14 additions & 5 deletions src/ORM/Connect/MySQLQuery.php
Expand Up @@ -64,11 +64,20 @@ public function getIterator(): Traversable
}
yield $data;
}
// Check for the method first since $this->handle is a mixed type
if (method_exists($this->handle, 'data_seek')) {
// Reset so the query can be iterated over again
$this->handle->data_seek(0);
}

// Reset so the query can be iterated over again
$this->rewind();
}
}

/**
* Rewind to the first row
*/
public function rewind(): void
{
// Check for the method first since $this->handle is a mixed type
if (method_exists($this->handle, 'data_seek')) {
$this->handle->data_seek(0);
}
}

Expand Down
10 changes: 9 additions & 1 deletion src/ORM/Connect/MySQLStatement.php
Expand Up @@ -117,9 +117,17 @@ public function getIterator(): Traversable
yield $row;
}

// Reset so the query can be iterated over again
$this->rewind();
}

/**
* Rewind to the first row
*/
public function rewind(): void
{
// Check for the method first since $this->statement isn't strongly typed
if (method_exists($this->statement, 'data_seek')) {
// Reset so the query can be iterated over again
$this->statement->data_seek(0);
}
}
Expand Down

0 comments on commit ae49e13

Please sign in to comment.