1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Bdf\Prime\Query; |
4
|
|
|
|
5
|
|
|
require_once __DIR__ . '/../_files/BenchData.php'; |
6
|
|
|
|
7
|
|
|
use Bdf\Prime\Bench\BenchData; |
8
|
|
|
use Bdf\Prime\Bench\User; |
9
|
|
|
use Bdf\Prime\Cache\ArrayCache; |
10
|
|
|
use Bdf\Prime\Collection\EntityCollection; |
11
|
|
|
use Bdf\Prime\Connection\ConnectionConfig; |
|
|
|
|
12
|
|
|
use Bdf\Prime\ConnectionManager; |
13
|
|
|
use Bdf\Prime\Locatorizable; |
14
|
|
|
use Bdf\Prime\Repository\EntityRepository; |
15
|
|
|
use Bdf\Prime\Repository\Write\BufferedWriter; |
16
|
|
|
use Bdf\Prime\ServiceLocator; |
17
|
|
|
use Bdf\Prime\Types\ArrayType; |
18
|
|
|
use BenchCaseAdapter; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Bench bulk operations using collections |
22
|
|
|
* |
23
|
|
|
* @Revs(10) |
24
|
|
|
*/ |
25
|
|
|
class BulkOperationBench extends BenchCaseAdapter |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* @var ServiceLocator |
29
|
|
|
*/ |
30
|
|
|
protected $prime; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var BenchData |
34
|
|
|
*/ |
35
|
|
|
protected $data; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @var ArrayCache |
39
|
|
|
*/ |
40
|
|
|
protected $cache; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @var EntityRepository |
44
|
|
|
*/ |
45
|
|
|
protected $repository; |
46
|
|
|
|
47
|
|
|
|
48
|
|
|
|
49
|
|
|
public function setUp() |
50
|
|
|
{ |
51
|
|
|
$this->cache = new ArrayCache(); |
52
|
|
|
$this->prime = new ServiceLocator(); |
53
|
|
|
$this->prime->connections()->declareConnection('test', BENCH_CONNECTION); |
54
|
|
|
$this->prime->connection('test')->getConfiguration()->getTypes()->register(ArrayType::class, 'array'); |
|
|
|
|
55
|
|
|
Locatorizable::configure($this->prime); |
|
|
|
|
56
|
|
|
|
57
|
|
|
$this->data = new BenchData($this->prime); |
58
|
|
|
//$this->data->addAllData(); |
59
|
|
|
$this->data->addBulkUsers(); |
60
|
|
|
|
61
|
|
|
$this->repository = $this->prime->repository(User::class); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* {@inheritdoc} |
66
|
|
|
*/ |
67
|
|
|
public function tearDown() |
68
|
|
|
{ |
69
|
|
|
$this->data->clear(); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @Groups({"update"}) |
74
|
|
|
*/ |
75
|
|
|
public function bench_bulk_update_native() |
76
|
|
|
{ |
77
|
|
|
/** @var User[] $users */ |
78
|
|
|
$users = $this->repository->all(); |
|
|
|
|
79
|
|
|
|
80
|
|
|
foreach ($users as $user) { |
81
|
|
|
$user->roles = [1]; |
82
|
|
|
$this->repository->update($user, ['roles']); |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @Groups({"update"}) |
88
|
|
|
*/ |
89
|
|
|
public function bench_bulk_update_collection() |
90
|
|
|
{ |
91
|
|
|
/** @var EntityCollection $users */ |
92
|
|
|
$users = $this->repository->wrapAs('collection')->all(); |
93
|
|
|
$users->update(['roles' => [1]]); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @Groups({"update"}) |
98
|
|
|
*/ |
99
|
|
|
public function bench_bulk_update_buffered_writer() |
100
|
|
|
{ |
101
|
|
|
/** @var User[] $users */ |
102
|
|
|
$users = $this->repository->all(); |
103
|
|
|
$writer = new BufferedWriter($this->repository); |
104
|
|
|
|
105
|
|
|
foreach ($users as $user) { |
106
|
|
|
$user->roles = [1]; |
107
|
|
|
$writer->update($user, ['attributes' => ['roles']]); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
$writer->flush(); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* @Groups({"load"}) |
115
|
|
|
*/ |
116
|
|
|
public function bench_bulk_load_native() |
117
|
|
|
{ |
118
|
|
|
/** @var User[] $users */ |
119
|
|
|
$users = $this->repository->all(); |
120
|
|
|
|
121
|
|
|
foreach ($users as $user) { |
122
|
|
|
$this->repository->loadRelations($user, 'customer'); |
123
|
|
|
} |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* @Groups({"load"}) |
128
|
|
|
*/ |
129
|
|
|
public function bench_bulk_load_collection() |
130
|
|
|
{ |
131
|
|
|
/** @var EntityCollection $users */ |
132
|
|
|
$users = $this->repository->wrapAs('collection')->all(); |
133
|
|
|
$users->load('customer'); |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* @Groups({"delete"}) |
138
|
|
|
*/ |
139
|
|
|
public function bench_bulk_delete_native() |
140
|
|
|
{ |
141
|
|
|
/** @var User[] $users */ |
142
|
|
|
$users = $this->repository->all(); |
143
|
|
|
|
144
|
|
|
foreach ($users as $user) { |
145
|
|
|
$this->repository->delete($user); |
146
|
|
|
} |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
/** |
150
|
|
|
* @Groups({"delete"}) |
151
|
|
|
*/ |
152
|
|
|
public function bench_bulk_delete_collection() |
153
|
|
|
{ |
154
|
|
|
/** @var EntityCollection $users */ |
155
|
|
|
$users = $this->repository->wrapAs('collection')->all(); |
156
|
|
|
$users->delete(); |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* @Groups({"delete"}) |
161
|
|
|
*/ |
162
|
|
|
public function bench_bulk_delete_writer() |
163
|
|
|
{ |
164
|
|
|
$writer = $this->repository->writer(); |
165
|
|
|
|
166
|
|
|
foreach ($this->repository->all() as $user) { |
167
|
|
|
$writer->delete($user); |
168
|
|
|
} |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
/** |
172
|
|
|
* @Groups({"delete"}) |
173
|
|
|
*/ |
174
|
|
|
public function bench_bulk_delete_buffered_writer() |
175
|
|
|
{ |
176
|
|
|
$writer = new BufferedWriter($this->repository); |
177
|
|
|
|
178
|
|
|
foreach ($this->repository->all() as $user) { |
179
|
|
|
$writer->delete($user); |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
$writer->flush(); |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
/** |
186
|
|
|
* @Groups({"save"}) |
187
|
|
|
*/ |
188
|
|
|
public function bench_bulk_save_native() |
189
|
|
|
{ |
190
|
|
|
/** @var User[] $users */ |
191
|
|
|
$users = $this->repository->all(); |
192
|
|
|
|
193
|
|
|
foreach ($users as $user) { |
194
|
|
|
$this->repository->save($user); |
195
|
|
|
} |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
/** |
199
|
|
|
* @Groups({"save"}) |
200
|
|
|
*/ |
201
|
|
|
public function bench_bulk_save_collection() |
202
|
|
|
{ |
203
|
|
|
/** @var EntityCollection $users */ |
204
|
|
|
$users = $this->repository->wrapAs('collection')->all(); |
205
|
|
|
$users->save(); |
206
|
|
|
} |
207
|
|
|
} |
208
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths