1 | <?php |
||||
2 | |||||
3 | namespace Bdf\Prime; |
||||
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\Connection\ConnectionConfig; |
||||
0 ignored issues
–
show
|
|||||
10 | use Bdf\Prime\Query\Contract\Query\InsertQueryInterface; |
||||
11 | use Bdf\Prime\Repository\EntityRepository; |
||||
12 | use Bdf\Prime\Types\ArrayType; |
||||
13 | |||||
14 | /** |
||||
15 | * Bench sharding connection |
||||
16 | * |
||||
17 | * @Revs(10) |
||||
18 | * @Warmup(1) |
||||
19 | */ |
||||
20 | class ShardingBench extends \BenchCaseAdapter |
||||
21 | { |
||||
22 | /** |
||||
23 | * @var ServiceLocator |
||||
24 | */ |
||||
25 | protected $prime; |
||||
26 | |||||
27 | /** |
||||
28 | * @var BenchData |
||||
29 | */ |
||||
30 | protected $data; |
||||
31 | |||||
32 | /** |
||||
33 | * @var EntityRepository |
||||
34 | */ |
||||
35 | protected $repository; |
||||
36 | |||||
37 | /** |
||||
38 | * |
||||
39 | */ |
||||
40 | public function setUp() |
||||
41 | { |
||||
42 | $this->prime = new ServiceLocator(); |
||||
43 | $this->prime->connections()->declareConnection('test', [ |
||||
44 | 'adapter' => 'sqlite', |
||||
45 | 'memory' => true, |
||||
46 | 'dbname' => 'TEST', |
||||
47 | 'distributionKey' => 'id', |
||||
48 | 'shards' => [ |
||||
49 | 'shard1' => ['dbname' => 'TEST_SHARD1'], |
||||
50 | 'shard2' => ['dbname' => 'TEST_SHARD2'], |
||||
51 | ] |
||||
52 | ]); |
||||
53 | $this->prime->connection('test')->getConfiguration()->getTypes()->register(ArrayType::class, 'array'); |
||||
0 ignored issues
–
show
The method
getConfiguration() does not exist on Bdf\Prime\Connection\ConnectionInterface . Since it exists in all sub-types, consider adding an abstract or default implementation to Bdf\Prime\Connection\ConnectionInterface .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
54 | Locatorizable::configure($this->prime); |
||||
0 ignored issues
–
show
$this->prime of type Bdf\Prime\ServiceLocator is incompatible with the type Closure expected by parameter $locator of Bdf\Prime\Locatorizable::configure() .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
55 | |||||
56 | $this->data = new BenchData($this->prime); |
||||
57 | $this->data->addBulkUsers(false); |
||||
58 | |||||
59 | $this->repository = $this->prime->repository(User::class); |
||||
60 | } |
||||
61 | |||||
62 | /** |
||||
63 | * {@inheritdoc} |
||||
64 | */ |
||||
65 | public function tearDown() |
||||
66 | { |
||||
67 | $this->data->clear(); |
||||
68 | } |
||||
69 | |||||
70 | /** |
||||
71 | * @Groups({"count"}) |
||||
72 | */ |
||||
73 | public function bench_count() |
||||
74 | { |
||||
75 | return $this->repository->count(['id' => '23000123']) > 0; |
||||
76 | } |
||||
77 | |||||
78 | /** |
||||
79 | * @Groups({"count"}) |
||||
80 | */ |
||||
81 | public function bench_countKeyValue() |
||||
82 | { |
||||
83 | return $this->repository->queries()->countKeyValue(['id' => '23000123']) > 0; |
||||
84 | } |
||||
85 | |||||
86 | /** |
||||
87 | * @Groups({"findById"}) |
||||
88 | */ |
||||
89 | public function bench_findById() |
||||
90 | { |
||||
91 | return $this->repository->queries()->findById('23000123'); |
||||
92 | } |
||||
93 | |||||
94 | /** |
||||
95 | * @Groups({"findById"}) |
||||
96 | */ |
||||
97 | public function bench_builder_get() |
||||
98 | { |
||||
99 | return $this->repository->builder()->get('23000123'); |
||||
0 ignored issues
–
show
The method
get() does not exist on Bdf\Prime\Query\QueryInterface . It seems like you code against a sub-type of said class. However, the method does not exist in Bdf\Prime\Query\SqlQueryInterface . Are you sure you never get one of those?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
100 | } |
||||
101 | |||||
102 | /** |
||||
103 | * @Groups({"search"}) |
||||
104 | */ |
||||
105 | public function bench_search_keyValue() |
||||
106 | { |
||||
107 | return $this->repository->keyValue([ |
||||
0 ignored issues
–
show
The method
keyValue() does not exist on Bdf\Prime\Repository\EntityRepository . Since you implemented __call , consider adding a @method annotation.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
108 | 'name' => 'user Common 123', |
||||
109 | 'customer.id' => '330000', |
||||
110 | ])->first(); |
||||
111 | } |
||||
112 | |||||
113 | /** |
||||
114 | * @Groups({"search"}) |
||||
115 | */ |
||||
116 | public function bench_search_builder() |
||||
117 | { |
||||
118 | return $this->repository->builder()->where([ |
||||
119 | 'name' => 'user Common 123', |
||||
120 | 'customer.id' => '330000', |
||||
121 | ])->first(); |
||||
122 | } |
||||
123 | |||||
124 | /** |
||||
125 | * @Groups({"delete"}) |
||||
126 | */ |
||||
127 | public function bench_delete_keyValue() |
||||
128 | { |
||||
129 | $id = '23000'.str_pad(rand(1, 500), 3, '0', STR_PAD_LEFT); |
||||
130 | return $this->repository->keyValue('id', $id)->delete(); |
||||
131 | } |
||||
132 | |||||
133 | /** |
||||
134 | * @Groups({"delete"}) |
||||
135 | */ |
||||
136 | public function bench_delete_keyValue_cached() |
||||
137 | { |
||||
138 | static $query; |
||||
139 | |||||
140 | if (!$query) { |
||||
141 | $query = $this->repository->keyValue(); |
||||
142 | } |
||||
143 | |||||
144 | $id = '23000'.str_pad(rand(1, 500), 3, '0', STR_PAD_LEFT); |
||||
145 | return $query->where('id', $id)->delete(); |
||||
146 | } |
||||
147 | |||||
148 | /** |
||||
149 | * @Groups({"delete"}) |
||||
150 | */ |
||||
151 | public function bench_delete_builder() |
||||
152 | { |
||||
153 | $id = '23000'.str_pad(rand(1, 500), 3, '0', STR_PAD_LEFT); |
||||
154 | return $this->repository->builder()->where('id', $id)->delete(); |
||||
155 | } |
||||
156 | |||||
157 | /** |
||||
158 | * @Groups({"update"}) |
||||
159 | */ |
||||
160 | public function bench_update_builder() |
||||
161 | { |
||||
162 | $id = '23000'.str_pad(rand(1, 500), 3, '0', STR_PAD_LEFT); |
||||
163 | return $this->repository->builder()->where('id', $id)->update(['name' => 'Bob']); |
||||
164 | } |
||||
165 | |||||
166 | /** |
||||
167 | * @Groups({"update"}) |
||||
168 | */ |
||||
169 | public function bench_update_keyValue() |
||||
170 | { |
||||
171 | $id = '23000'.str_pad(rand(1, 500), 3, '0', STR_PAD_LEFT); |
||||
172 | return $this->repository->keyValue('id', $id)->update(['name' => 'Bob']); |
||||
173 | } |
||||
174 | |||||
175 | /** |
||||
176 | * @Groups({"update"}) |
||||
177 | */ |
||||
178 | public function bench_update_keyValue_cached() |
||||
179 | { |
||||
180 | static $query; |
||||
181 | |||||
182 | if (!$query) { |
||||
183 | $query = $this->repository->keyValue(); |
||||
184 | } |
||||
185 | |||||
186 | $id = '23000'.str_pad(rand(1, 500), 3, '0', STR_PAD_LEFT); |
||||
187 | return $query->where('id', $id)->update(['name' => 'Bob']); |
||||
188 | } |
||||
189 | |||||
190 | /** |
||||
191 | * @Groups({"insert"}) |
||||
192 | */ |
||||
193 | public function bench_insert_optimised() |
||||
194 | { |
||||
195 | /** @var InsertQueryInterface $insert */ |
||||
196 | $insert = $this->repository->queries()->make(InsertQueryInterface::class); |
||||
197 | |||||
198 | for ($i = 0; $i < 100; ++$i) { |
||||
199 | $insert->values([ |
||||
200 | 'id' => 6000000 + $i, |
||||
201 | 'name' => 'bulk user '.$i, |
||||
202 | 'roles' => ['2'], |
||||
203 | 'customer.id' => 1, |
||||
204 | ]); |
||||
205 | $insert->execute(); |
||||
206 | } |
||||
207 | |||||
208 | // Clear data set |
||||
209 | $this->repository->where('id', 'between', [6000000, 7000000])->delete(); |
||||
210 | } |
||||
211 | |||||
212 | /** |
||||
213 | * @Groups({"insert"}) |
||||
214 | */ |
||||
215 | public function bench_insert_builder() |
||||
216 | { |
||||
217 | for ($i = 0; $i < 100; ++$i) { |
||||
218 | $this->repository->builder()->insert([ |
||||
219 | 'id' => 6000000 + $i, |
||||
220 | 'name' => 'bulk user '.$i, |
||||
221 | 'roles' => ['2'], |
||||
222 | 'customer.id' => 1, |
||||
223 | ]); |
||||
224 | } |
||||
225 | |||||
226 | // Clear data set |
||||
227 | $this->repository->where('id', 'between', [6000000, 7000000])->delete(); |
||||
228 | } |
||||
229 | } |
||||
230 |
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