Skip to content

Commit d0264ae

Browse files
committed
Script: Cron: optimization of script to do only one flush per URL to avoid spending 5 seconds per user - refs BT#20351
1 parent 5c6198a commit d0264ae

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

tests/scripts/synchronize_user_base_from_csv.php

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@
113113
continue;
114114
}
115115

116+
$urlUsersIdList = [];
116117
$CSVUsers = Import::csvToArray($filename, ',');
117118

118119
if (!$CSVUsers) {
@@ -225,22 +226,9 @@
225226
}
226227
}
227228
}
228-
229-
try {
230-
$entityManager->flush();
231-
} catch (OptimisticLockException $e) {
232-
echo "Error processing user '{$username}': " . $e->getMessage() . "\n";
233-
error_log("Error processing user '{$username}': " . $e->getMessage());
234-
echo "Trace: " . $e->getTraceAsString() . "\n";
235-
continue;
236-
}
237-
238-
if ($debug) {
239-
echo 'Sent to DB ' . $username . " with user id = " . $user->getId() . "\n";
240-
}
241-
UrlManager::add_user_to_url($user->getId(), $accessUrlId);
242229
}
243230

231+
$urlUsersIdList[] = $user->getId();
244232
$allCSVUsers[$username] = $user;
245233

246234
} catch (Exception $e) {
@@ -250,6 +238,21 @@
250238
continue;
251239
}
252240
}
241+
try {
242+
$entityManager->flush();
243+
} catch (OptimisticLockException $e) {
244+
echo "Error processing users for URL '{$accessUrlId}': " . $e->getMessage() . "\n";
245+
error_log("Error processing users for URL '{$accessUrlId}': " . $e->getMessage());
246+
echo "Trace: " . $e->getTraceAsString() . "\n";
247+
continue;
248+
}
249+
if ($debug) {
250+
echo 'Sent users ' . print_r($urlUsersIdList,1) . ' to DB for URL ' . $accessUrlId . "\n";
251+
}
252+
$accessUrlList = [];
253+
$accessUrlList[] = $accessUrlId;
254+
UrlManager::add_users_to_urls($urlUsersIdList, $accessUrlList);
255+
253256
}
254257

255258
// Disable or delete user accounts not found in any CSV file depending on $deleteUsersNotFoundInCSV

0 commit comments

Comments
 (0)