Skip to content
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

feat: [Command] add options for spark optimize command #9054

Open
wants to merge 9 commits into
base: 4.6
Choose a base branch
from

Conversation

warcooft
Copy link
Contributor

@warcooft warcooft commented Jul 20, 2024

Description

To make this command more flexible. This PR provides options to allow us to easily enable or disable cache configuration.

Usage

protected $usage = 'optimize [-c] [-l] [-d]';

Options

protected $options = [
    'c' => 'Enable config cache',
    'l' => 'Enable locator cache',
    'd' => 'Disable config and locator caching',
];

Example

// Enable configCache and locatorCache.
php spark optimize 

// Enable configCache only and ignore the others.
php spark optimize -c 

// Enable locatorCache only and ignore the others.
php spark optimize -l 

// Disable config and locator caching
php spark optimize -d

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

@paulbalandan
Copy link
Member

I think it would be easier to understand the options if we use long options names, like --config-only.

@paulbalandan paulbalandan added enhancement PRs that improve existing functionalities tests needed Pull requests that need tests 4.6 labels Jul 20, 2024
@kenjis
Copy link
Member

kenjis commented Jul 20, 2024

-r is also a bit difficult to understand. --disable or -d may be better?

@warcooft
Copy link
Contributor Author

Using long options names i think would take extra time to write it. it's better if we keep it simple.
Or we can create additional options as aliases for each option?

@warcooft
Copy link
Contributor Author

@kenjis -d I think is much better.

@kenjis
Copy link
Member

kenjis commented Jul 24, 2024

Or we can create additional options as aliases for each option?

There is no commands that having a short and long options for one action.
So, use short options or use long options.

@kenjis
Copy link
Member

kenjis commented Jul 24, 2024

What if you specify all options spark optimize -c -l -r?

@kenjis
Copy link
Member

kenjis commented Jul 29, 2024

Please fix coding style, and add test code to prove this works fine.

Copy link
Contributor Author

@warcooft warcooft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have much experience with unit testing, so please let me know if it seems right.

@datamweb
Copy link
Contributor

Good PR, every person to run actions.

@@ -99,32 +115,73 @@ private function removeFile(string $cache): void
}
}

private function enableCaching(): void
private function enableCaching(?bool $enableConfigCache, ?bool $enableLocatorCache, ?bool $disable): void
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the method enableCaching() does disable caching?
It is strange and not intuitive.
Please add a new private method to disable caching.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@kenjis
Copy link
Member

kenjis commented Jul 29, 2024

spark optimize -d does not reinstall dev packages.

@kenjis kenjis added the docs needed Pull requests needing documentation write-ups and/or revisions. label Jul 30, 2024
@warcooft
Copy link
Contributor Author

Can you guys run the workflow again. It seems everything is fine now.

*
* @return array<string, string>
*/
private function disableCaching(): array
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I see the method name disableCaching(), I imagine the method disables caching.
But this method just returns an array.
Therefore the method name or the implementation is not good.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i will send an update, this makes it more flexible.

@@ -99,32 +123,100 @@ private function removeFile(string $cache): void
}
}

private function enableCaching(): void
private function runCaching(?bool $enableConfigCache, ?bool $enableLocatorCache, ?bool $disable): void
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand what the runConfig() method dose when I see the method name.
Is updateConfigFile() better?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I see the method name disableCaching(), I imagine the method disables caching.
But this method just returns an array.
Therefore the method name or the implementation is not good.

If disabelCaching() and enableCaching() does its job completely, I don't think runCaching() is needed any more. we just need a process like this.

public function run(array $params)
    {
        // Parse options
        $enableConfigCache  = CLI::getOption('c');
        $enableLocatorCache = CLI::getOption('l');
        $disable            = CLI::getOption('d');

        try {
            if ($disable === true) {
                $this->disableCaching();
                $this->reinstallDevPackages();
            } else {
                $this->enableCaching(['config' => $enableConfigCache, 'locator' => $enableLocatorCache]);
                $this->removeDevPackages();
            }

            $this->clearCache();

        } catch (RuntimeException) {
            CLI::error('The "spark optimize" failed.');

            return EXIT_ERROR;
        }

        return EXIT_SUCCESS;
    }

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good! That will be easier to understand.

@kenjis kenjis removed the tests needed Pull requests that need tests label Aug 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4.6 docs needed Pull requests needing documentation write-ups and/or revisions. enhancement PRs that improve existing functionalities
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants