-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(ZMS-3399): refactoring #732
Conversation
WalkthroughThe changes in this pull request focus on the Changes
Possibly related PRs
Suggested reviewers
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Outside diff range and nitpick comments (1)
zmsdb/src/Zmsdb/Source/Dldb.php (1)
33-33
: Consider adding error handling for updateAvailabilityThe refactoring improves separation of concerns by isolating the availability update logic. However, consider adding try-catch block around the updateAvailability call to handle potential errors gracefully.
if ($updateAvailability) { + try { $this->updateAvailability($providers); + } catch (\Exception $e) { + if (self::$verbose) { + print("Error updating availability: " . $e->getMessage() . "\n"); + } + throw $e; + } }Also applies to: 40-40, 44-47
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
zmsdb/src/Zmsdb/Source/Dldb.php
(3 hunks)
🔇 Additional comments (3)
zmsdb/src/Zmsdb/Source/Dldb.php (3)
17-17
: LGTM: Path construction is safe and consistent
The string concatenation change maintains functionality while improving readability.
21-22
: LGTM: Consistent brace style
The brace placement change aligns with coding style guidelines.
68-80
: LGTM: Improved method responsibility and logging
The method now has a clearer single responsibility and better logging. Let's verify the removal of $updateAvailability parameter doesn't break existing calls.
✅ Verification successful
The previous search might have been too specific. Let's broaden it to find any usage of the method and understand the class hierarchy to verify if there are any inherited calls that might be affected.
Based on the search results, I can now generate the final response:
Verified: Safe to remove $updateAvailability parameter
The method writeProviderList()
is only called internally within the Dldb class itself (in the same file) without any parameters. The class extends \BO\Zmsdb\Base
and there are no other classes inheriting from it that might be affected by this change. The parameter removal is safe.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Search for any direct calls to writeProviderList with parameters
rg -l "writeProviderList\([^)]+\)" --type php
Length of output: 47
Script:
#!/bin/bash
# Let's try a broader search for writeProviderList usage
rg "writeProviderList" --type php -A 2
# Also search for class usage to understand inheritance
rg "class.*Dldb" --type php
Length of output: 6123
protected function updateAvailability($providers) | ||
{ | ||
foreach ($providers as $provider) { | ||
$providerData = $provider->data; | ||
|
||
if (!$updateAvailability) { | ||
continue; | ||
} | ||
|
||
$scopes = (new \BO\Zmsdb\Scope())->readByProviderId($provider->getId()); | ||
foreach ($scopes as $scope) { | ||
$availabilities = (new \BO\Zmsdb\Availability())->readList($scope->getId()); | ||
|
||
foreach ($availabilities as $availability) { | ||
if ($availability->slotTimeInMinutes === $providerData['slotTimeInMinutes']) { | ||
if ((int) $availability->slotTimeInMinutes === (int) $providerData['slotTimeInMinutes']) { | ||
continue; | ||
} | ||
|
||
$availability->slotTimeInMinutes = $providerData['slotTimeInMinutes']; | ||
$updatedEntity = (new \BO\Zmsdb\Availability()) | ||
(new \BO\Zmsdb\Availability()) | ||
->updateEntity($availability->getId(), $availability, 2); | ||
|
||
//if (isset($providerData['forceSlotTimeUpdate']) && $providerData['forceSlotTimeUpdate']) { | ||
// (new \BO\Zmsdb\Slot)->writeByAvailability($updatedEntity, \App::$now); | ||
// (new \BO\Zmsdb\Helper\CalculateSlots(\App::DEBUG)) | ||
// ->writePostProcessingByScope($updatedEntity->scope, \App::$now); | ||
//} | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Consider performance and monitoring improvements
The new method handles availability updates but has some areas for improvement:
- Multiple database calls in nested loops could impact performance
- No transaction handling for atomic updates
- Missing logging for tracking changes
Consider these improvements:
protected function updateAvailability($providers)
{
+ $startTime = microtime(true);
+ $updatedCount = 0;
+ \BO\Zmsdb\Connection\Select::setTransaction();
+
foreach ($providers as $provider) {
$providerData = $provider->data;
$scopes = (new \BO\Zmsdb\Scope())->readByProviderId($provider->getId());
+ $availabilityQuery = new \BO\Zmsdb\Availability();
+
foreach ($scopes as $scope) {
$availabilities = (new \BO\Zmsdb\Availability())->readList($scope->getId());
foreach ($availabilities as $availability) {
if ((int) $availability->slotTimeInMinutes === (int) $providerData['slotTimeInMinutes']) {
continue;
}
$availability->slotTimeInMinutes = $providerData['slotTimeInMinutes'];
- (new \BO\Zmsdb\Availability())
- ->updateEntity($availability->getId(), $availability, 2);
+ $availabilityQuery->updateEntity($availability->getId(), $availability, 2);
+ $updatedCount++;
}
}
}
+
+ \BO\Zmsdb\Connection\Select::writeCommit();
+
+ if (self::$verbose) {
+ $time = round(microtime(true) - $startTime, 3);
+ print("Updated $updatedCount availabilities in $time seconds\n\n");
+ }
}
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
protected function updateAvailability($providers) | |
{ | |
foreach ($providers as $provider) { | |
$providerData = $provider->data; | |
if (!$updateAvailability) { | |
continue; | |
} | |
$scopes = (new \BO\Zmsdb\Scope())->readByProviderId($provider->getId()); | |
foreach ($scopes as $scope) { | |
$availabilities = (new \BO\Zmsdb\Availability())->readList($scope->getId()); | |
foreach ($availabilities as $availability) { | |
if ($availability->slotTimeInMinutes === $providerData['slotTimeInMinutes']) { | |
if ((int) $availability->slotTimeInMinutes === (int) $providerData['slotTimeInMinutes']) { | |
continue; | |
} | |
$availability->slotTimeInMinutes = $providerData['slotTimeInMinutes']; | |
$updatedEntity = (new \BO\Zmsdb\Availability()) | |
(new \BO\Zmsdb\Availability()) | |
->updateEntity($availability->getId(), $availability, 2); | |
//if (isset($providerData['forceSlotTimeUpdate']) && $providerData['forceSlotTimeUpdate']) { | |
// (new \BO\Zmsdb\Slot)->writeByAvailability($updatedEntity, \App::$now); | |
// (new \BO\Zmsdb\Helper\CalculateSlots(\App::DEBUG)) | |
// ->writePostProcessingByScope($updatedEntity->scope, \App::$now); | |
//} | |
} | |
} | |
} | |
protected function updateAvailability($providers) | |
{ | |
$startTime = microtime(true); | |
$updatedCount = 0; | |
\BO\Zmsdb\Connection\Select::setTransaction(); | |
foreach ($providers as $provider) { | |
$providerData = $provider->data; | |
$scopes = (new \BO\Zmsdb\Scope())->readByProviderId($provider->getId()); | |
$availabilityQuery = new \BO\Zmsdb\Availability(); | |
foreach ($scopes as $scope) { | |
$availabilities = (new \BO\Zmsdb\Availability())->readList($scope->getId()); | |
foreach ($availabilities as $availability) { | |
if ((int) $availability->slotTimeInMinutes === (int) $providerData['slotTimeInMinutes']) { | |
continue; | |
} | |
$availability->slotTimeInMinutes = $providerData['slotTimeInMinutes']; | |
$availabilityQuery->updateEntity($availability->getId(), $availability, 2); | |
$updatedCount++; | |
} | |
} | |
} | |
\BO\Zmsdb\Connection\Select::writeCommit(); | |
if (self::$verbose) { | |
$time = round(microtime(true) - $startTime, 3); | |
print("Updated $updatedCount availabilities in $time seconds\n\n"); | |
} | |
} |
Description
Short description or comments
Reference
Issues #XXX
Summary by CodeRabbit