mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
chore: fmt
This commit is contained in:
@@ -3469,23 +3469,23 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/documents')
|
||||
$document->setAttribute('$collectionId', $collection->getId());
|
||||
|
||||
static $relatedCollectionsCache = [];
|
||||
|
||||
|
||||
$relationships = \array_filter(
|
||||
$collection->getAttribute('attributes', []),
|
||||
fn ($attribute) => $attribute->getAttribute('type') === Database::VAR_RELATIONSHIP
|
||||
);
|
||||
|
||||
|
||||
// First collect all required related collection IDs
|
||||
$relatedCollectionIds = [];
|
||||
foreach ($relationships as $relationship) {
|
||||
$relatedCollectionId = $relationship->getAttribute('relatedCollection');
|
||||
$cacheKey = 'database_' . $database->getInternalId() . '_' . $relatedCollectionId;
|
||||
|
||||
|
||||
if (!isset($relatedCollectionsCache[$cacheKey])) {
|
||||
$relatedCollectionIds[$cacheKey] = $relatedCollectionId;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Fetch all required collections in a single batch if needed
|
||||
if (!empty($relatedCollectionIds)) {
|
||||
foreach ($relatedCollectionIds as $cacheKey => $relatedCollectionId) {
|
||||
|
||||
@@ -1919,7 +1919,7 @@ App::post('/v1/functions/:functionId/executions')
|
||||
static $functionCache = [];
|
||||
static $deploymentCache = [];
|
||||
static $buildCache = [];
|
||||
|
||||
|
||||
// Get function document with caching
|
||||
$cacheKey = $functionId;
|
||||
if (!isset($functionCache[$cacheKey])) {
|
||||
|
||||
@@ -810,35 +810,35 @@ App::get('/v1/users/:userId/memberships')
|
||||
}
|
||||
|
||||
$memberships = $user->getAttribute('memberships', []);
|
||||
|
||||
|
||||
// Get all team IDs to fetch in a single query
|
||||
$teamIds = array_map(function ($membership) {
|
||||
return $membership->getAttribute('teamId');
|
||||
}, $memberships);
|
||||
|
||||
|
||||
// Fetch all teams in a single query if there are any memberships
|
||||
$teams = [];
|
||||
if (!empty($teamIds)) {
|
||||
$teamsDocuments = $dbForProject->find('teams', [
|
||||
Query::equal('$id', $teamIds),
|
||||
]);
|
||||
|
||||
|
||||
// Index teams by ID for quick lookup
|
||||
foreach ($teamsDocuments as $team) {
|
||||
$teams[$team->getId()] = $team;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Now map memberships with team data
|
||||
$memberships = array_map(function ($membership) use ($teams, $user) {
|
||||
$teamId = $membership->getAttribute('teamId');
|
||||
$team = $teams[$teamId] ?? null;
|
||||
|
||||
|
||||
$membership
|
||||
->setAttribute('teamName', $team ? $team->getAttribute('name') : '')
|
||||
->setAttribute('userName', $user->getAttribute('name'))
|
||||
->setAttribute('userEmail', $user->getAttribute('email'));
|
||||
|
||||
|
||||
return $membership;
|
||||
}, $memberships);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user