[TASK] Speed-up update of translations 88/43388/2
authorXavier Perseguers <xavier@typo3.org>
Thu, 17 Sep 2015 09:31:18 +0000 (11:31 +0200)
committerXavier Perseguers <xavier@typo3.org>
Thu, 17 Sep 2015 10:42:07 +0000 (12:42 +0200)
Instead of updating a single extension and language per AJAX call, update
up to 10 extensions for a single language. This typically reduces the
number of AJAX calls and time to complete by a factor 5.

Change-Id: Ib3ae12b06ab0c4ce154c9a879aa435b9aebdccc1
Releases: master
Resolves: #69910
Reviewed-on: http://review.typo3.org/43388
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Loek Hilgersom <loek@netcoop.nl>
Tested-by: Loek Hilgersom <loek@netcoop.nl>
Reviewed-by: Xavier Perseguers <xavier@typo3.org>
Tested-by: Xavier Perseguers <xavier@typo3.org>
typo3/sysext/lang/Classes/Controller/LanguageController.php

index 1fd8b88..ee03a84 100644 (file)
@@ -104,29 +104,41 @@ class LanguageController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionControl
         * @return void
         */
        public function updateLanguageAction(array $data) {
+               $numberOfExtensionsToUpdate = 10;
                $response = array(
                        'success'  => FALSE,
                        'progress' => 0,
                );
                if (!empty($data['locale'])) {
-                       $extension = $this->extensionRepository->findOneByOffset((int)$data['count']);
-                       if (!empty($extension)) {
-                               $allCount = (int)$this->extensionRepository->countAll();
-                               $offset = (int)$data['count'];
+                       $allCount = 0;
+                       for ($i = 0; $i < $numberOfExtensionsToUpdate; $i++) {
+                               $offset = (int)$data['count'] * $numberOfExtensionsToUpdate + $i;
+                               $extension = $this->extensionRepository->findOneByOffset($offset);
+                               if (empty($extension)) {
+                                       // No more extensions to update
+                                       break;
+                               }
+                               if ($allCount === 0) {
+                                       $allCount = (int)$this->extensionRepository->countAll();
+                               }
                                $extensionKey = $extension->getKey();
                                $result = $this->translationService->updateTranslation($extensionKey, $data['locale']);
                                $progress = round((($offset + 1) * 100) / $allCount, 2);
+                               $response['result'][$data['locale']][$extensionKey] = $result[$data['locale']];
                                if (empty($result[$extensionKey][$data['locale']]['error'])) {
-                                       $this->registryService->set($data['locale'], $GLOBALS['EXEC_TIME']);
-                                       $response = array(
-                                               'success'   => TRUE,
-                                               'result'    => $result,
-                                               'timestamp' => $GLOBALS['EXEC_TIME'],
-                                               'progress'  => $progress > 100 ? 100 : $progress,
-                                       );
+                                       $response['success'] = TRUE;
+                               } else {
+                                       // Could not update an extension, stop here!
+                                       $response['success'] = FALSE;
+                                       break;
                                }
                        }
                }
+               if ($response['success']) {
+                       $this->registryService->set($data['locale'], $GLOBALS['EXEC_TIME']);
+                       $response['timestamp'] = $GLOBALS['EXEC_TIME'];
+                       $response['progress'] = $progress > 100 ? 100 : $progress;
+               }
                $this->view->assign('response', $response);
        }