1616use TYPO3 \Flow \Exception ;
1717use TYPO3 \Flow \Persistence \PersistenceManagerInterface ;
1818use TYPO3 \Jobqueue \Common \Job \JobManager ;
19+ use TYPO3 \TYPO3CR \Domain \Factory \NodeFactory ;
1920use TYPO3 \TYPO3CR \Domain \Model \NodeData ;
2021use TYPO3 \TYPO3CR \Domain \Model \NodeInterface ;
2122use TYPO3 \TYPO3CR \Domain \Repository \WorkspaceRepository ;
@@ -34,6 +35,12 @@ class NodeIndexQueueCommandController extends CommandController {
3435 */
3536 protected $ jobManager ;
3637
38+ /**
39+ * @var PersistenceManagerInterface
40+ * @Flow\Inject
41+ */
42+ protected $ persistenceManager ;
43+
3744 /**
3845 * @Flow\Inject
3946 * @var NodeTypeMappingBuilder
@@ -65,6 +72,8 @@ class NodeIndexQueueCommandController extends CommandController {
6572 protected $ logger ;
6673
6774 /**
75+ * Index all nodes by creating a new index and when everything was completed, switch the index alias.
76+ *
6877 * @param string $workspace
6978 */
7079 public function buildCommand ($ workspace = NULL ) {
@@ -97,22 +106,26 @@ protected function indexWorkspace($workspaceName, $indexPostfix) {
97106 $ offset = 0 ;
98107 $ batchSize = 100 ;
99108 while (TRUE ) {
100- $ result = $ this ->nodeDataRepository ->findAllBySiteAndWorkspace ($ workspaceName , $ offset , $ batchSize );
101- if ($ result === array ()) {
102- break ;
103- }
109+ $ iterator = $ this ->nodeDataRepository ->findAllBySiteAndWorkspace ($ workspaceName , $ offset , $ batchSize );
110+
104111 $ jobData = [];
105- foreach ($ result as $ data ) {
112+
113+ foreach ($ this ->nodeDataRepository ->iterate ($ iterator ) as $ data ) {
106114 $ jobData [] = [
107115 'nodeIdentifier ' => $ data ['nodeIdentifier ' ],
108116 'dimensions ' => $ data ['dimensions ' ]
109-
110117 ];
111118 }
119+
120+ if ($ jobData === []) {
121+ break ;
122+ }
123+
112124 $ indexingJob = new IndexingJob ($ indexPostfix , $ workspaceName , $ jobData );
113125 $ this ->jobManager ->queue ('Flowpack.ElasticSearch.ContentRepositoryQueueIndexer ' , $ indexingJob );
114126 $ this ->output ('. ' );
115127 $ offset += $ batchSize ;
128+ $ this ->persistenceManager ->clearState ();
116129 }
117130 }
118131
0 commit comments