44
55use Swoole \Database \PDOConfig ;
66use Swoole \Database \PDOPool ;
7- use Swoole \Runtime ;
87use Utopia \Cache \Adapter \None as NoCache ;
98use Utopia \Cache \Cache ;
109use Utopia \CLI \Console ;
2423
2524// Global pools for faster document generation
2625$ namesPool = ['Alice ' , 'Bob ' , 'Carol ' , 'Dave ' , 'Eve ' , 'Frank ' , 'Grace ' , 'Heidi ' , 'Ivan ' , 'Judy ' , 'Mallory ' , 'Niaj ' , 'Olivia ' , 'Peggy ' , 'Quentin ' , 'Rupert ' , 'Sybil ' , 'Trent ' , 'Uma ' , 'Victor ' ];
27- $ genresPool = ['fashion ' ,'food ' ,'travel ' ,'music ' ,'lifestyle ' ,'fitness ' ,'diy ' ,'sports ' ,'finance ' ];
28- $ tagsPool = ['short ' ,'quick ' ,'easy ' ,'medium ' ,'hard ' ];
26+ $ genresPool = ['fashion ' , 'food ' , 'travel ' , 'music ' , 'lifestyle ' , 'fitness ' , 'diy ' , 'sports ' , 'finance ' ];
27+ $ tagsPool = ['short ' , 'quick ' , 'easy ' , 'medium ' , 'hard ' ];
2928
3029/**
3130 * @Example
6968 'attrs ' => MySQL::getPDOAttributes (),
7069 ],
7170 'postgres ' => [
72- 'postgres ' => [
73- 'host ' => 'postgres ' ,
74- 'port ' => 5432 ,
75- 'user ' => 'postgres ' ,
76- 'pass ' => 'password ' ,
77- 'dsn ' => static fn (string $ host , int $ port ) => "pgsql:host= {$ host };port= {$ port }" ,
78- 'driver ' => 'pgsql ' ,
79- 'adapter ' => Postgres::class,
80- 'attrs ' => Postgres::getPDOAttributes (),
81- ],
71+ 'host ' => 'postgres ' ,
72+ 'port ' => 5432 ,
73+ 'user ' => 'postgres ' ,
74+ 'pass ' => 'password ' ,
75+ 'dsn ' => static fn (string $ host , int $ port ) => "pgsql:host= {$ host };port= {$ port }" ,
76+ 'driver ' => 'pgsql ' ,
77+ 'adapter ' => Postgres::class,
78+ 'attrs ' => Postgres::getPDOAttributes (),
8279 ],
8380 ];
8481
@@ -175,7 +172,7 @@ function createDocuments(Database $database): void
175172 $ bytes = \random_bytes (intdiv ($ length + 1 , 2 ));
176173 $ text = \substr (\bin2hex ($ bytes ), 0 , $ length );
177174 $ tagCount = \mt_rand (1 , count ($ tagsPool ));
178- $ tagKeys = (array ) \array_rand ($ tagsPool , $ tagCount );
175+ $ tagKeys = (array )\array_rand ($ tagsPool , $ tagCount );
179176 $ tags = \array_map (fn ($ k ) => $ tagsPool [$ k ], $ tagKeys );
180177
181178 $ documents [] = new Document ([
@@ -186,12 +183,12 @@ function createDocuments(Database $database): void
186183 ...array_map (fn () => Permission::update (Role::user (mt_rand (0 , 999999999 ))), range (1 , 3 )),
187184 ...array_map (fn () => Permission::delete (Role::user (mt_rand (0 , 999999999 ))), range (1 , 3 )),
188185 ],
189- 'author ' => $ namesPool [\array_rand ($ namesPool )],
186+ 'author ' => $ namesPool [\array_rand ($ namesPool )],
190187 'created ' => DateTime::now (),
191- 'text ' => $ text ,
192- 'genre ' => $ genresPool [\array_rand ($ genresPool )],
193- 'views ' => \mt_rand (0 , 999999 ),
194- 'tags ' => $ tags ,
188+ 'text ' => $ text ,
189+ 'genre ' => $ genresPool [\array_rand ($ genresPool )],
190+ 'views ' => \mt_rand (0 , 999999 ),
191+ 'tags ' => $ tags ,
195192 ]);
196193 }
197194 $ time = \microtime (true ) - $ start ;
0 commit comments