|
2 | 2 |
|
3 | 3 | namespace headstart\persistence; |
4 | 4 |
|
5 | | - |
6 | 5 | /** |
7 | 6 | * This class implements the PersistenceInterface and provides methods to interact with the database. |
8 | 7 | */ |
9 | 8 | class DispatchingPersistence implements Persistence |
10 | 9 | { |
11 | | - private Persistence $oldPersistence; |
12 | 10 | private Persistence $newPersistence; |
13 | | - private int|float $shiftReadPercentage; |
14 | | - |
15 | 11 |
|
16 | | - public function __construct(Persistence $oldPersistence, Persistence $newPersistence, $shiftReadPercentage) |
| 12 | + public function __construct(Persistence $newPersistence) |
17 | 13 | { |
18 | | - $this->shiftReadPercentage = $shiftReadPercentage; |
19 | | - $this->oldPersistence = $oldPersistence; |
20 | 14 | $this->newPersistence = $newPersistence; |
21 | 15 | } |
22 | 16 |
|
23 | 17 | public function createVisualization($vis_id, $vis_title, $input_json, $query, $dirty_query, $params_json): void |
24 | 18 | { |
25 | | - $this->oldPersistence->createVisualization($vis_id, $vis_title, $input_json, $query, $dirty_query, $params_json); |
26 | 19 | $this->newPersistence->createVisualization($vis_id, $vis_title, $input_json, $query, $dirty_query, $params_json); |
27 | 20 | } |
28 | 21 |
|
29 | 22 | public function getRevision($vis_id, $rev_id): array|bool |
30 | 23 | { |
31 | | - $randomFloat = getRandomFloat(); |
32 | | - |
33 | | - if (($randomFloat * 100) > ($this->shiftReadPercentage * 100)) { |
34 | | - $result = $this->oldPersistence->getRevision($vis_id, $rev_id); |
35 | | - } else { |
36 | | - $result = $this->newPersistence->getRevision($vis_id, $rev_id); |
37 | | - } |
38 | | - |
39 | | - return $result; |
| 24 | + return $this->newPersistence->getRevision($vis_id, $rev_id); |
40 | 25 | } |
41 | 26 |
|
42 | 27 | public function writeRevision($vis_id, $data): void |
43 | 28 | { |
44 | | - $this->oldPersistence->writeRevision($vis_id, $data); |
45 | 29 | $this->newPersistence->writeRevision($vis_id, $data); |
46 | 30 | } |
47 | 31 |
|
48 | 32 | public function existsVisualization($vis_id): array|bool |
49 | 33 | { |
50 | | - $randomFloat = getRandomFloat(); |
51 | | - |
52 | | - if ($randomFloat * 100 > $this->shiftReadPercentage * 100) { |
53 | | - $result = $this->oldPersistence->existsVisualization($vis_id); |
54 | | - } else { |
55 | | - $result = $this->newPersistence->existsVisualization($vis_id); |
56 | | - } |
57 | | - |
58 | | - return $result; |
| 34 | + return $this->newPersistence->existsVisualization($vis_id); |
59 | 35 | } |
60 | 36 |
|
61 | 37 | public function getLastVersion($vis_id, $details, $context): array|bool |
62 | 38 | { |
63 | | - $randomFloat = getRandomFloat(); |
64 | | - |
65 | | - if ($randomFloat * 100 > $this->shiftReadPercentage * 100) { |
66 | | - $result = $this->oldPersistence->getLastVersion($vis_id, $details, $context); |
67 | | - } else { |
68 | | - $result = $this->newPersistence->getLastVersion($vis_id, $details, $context); |
69 | | - } |
70 | | - |
71 | | - return $result; |
| 39 | + return $this->newPersistence->getLastVersion($vis_id, $details, $context); |
72 | 40 | } |
73 | 41 |
|
74 | 42 | public function getLatestRevisions(): array|bool |
75 | 43 | { |
76 | | - $randomFloat = getRandomFloat(); |
77 | | - |
78 | | - if ($randomFloat * 100 > $this->shiftReadPercentage * 100) { |
79 | | - $result = $this->oldPersistence->getLatestRevisions(); |
80 | | - } else { |
81 | | - $result = $this->newPersistence->getLatestRevisions(); |
82 | | - } |
83 | | - |
84 | | - return $result; |
| 44 | + return $this->newPersistence->getLatestRevisions(); |
85 | 45 | } |
86 | 46 |
|
87 | 47 | public function getContext($vis_id): array|bool |
88 | 48 | { |
89 | | - $randomFloat = getRandomFloat(); |
90 | | - |
91 | | - if ($randomFloat * 100 > $this->shiftReadPercentage * 100) { |
92 | | - $result = $this->oldPersistence->getContext($vis_id); |
93 | | - } else { |
94 | | - $result = $this->newPersistence->getContext($vis_id); |
95 | | - } |
96 | | - |
97 | | - return $result; |
| 49 | + return $this->newPersistence->getContext($vis_id); |
98 | 50 | } |
99 | 51 |
|
100 | 52 | public function createID($string_array, $payload): string |
101 | 53 | { |
102 | | - $randomFloat = getRandomFloat(); |
103 | | - |
104 | | - if ($randomFloat * 100 > $this->shiftReadPercentage * 100) { |
105 | | - $result = $this->oldPersistence->createID($string_array, $payload); |
106 | | - } else { |
107 | | - $result = $this->newPersistence->createID($string_array, $payload); |
108 | | - } |
109 | | - |
110 | | - return $result; |
| 54 | + return $this->newPersistence->createID($string_array, $payload); |
111 | 55 | } |
112 | 56 | } |
113 | | - |
114 | | - |
115 | | -// function for random float number generation from 0 to 1 |
116 | | -function getRandomFloat(): float |
117 | | -{ |
118 | | - return mt_rand() / mt_getrandmax(); |
119 | | -} |
0 commit comments