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

#129 by pass when APP_ENV=testing. #130

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

zgetro
Copy link

@zgetro zgetro commented Nov 9, 2024

i think this will be better solution for issue129

@spiritix
Copy link
Owner

Thanks for the contribution. I agree that it's usually a good idea to turn off Lada Cache during testing. However, I don't think it's a good idea to hardcode this behaviour. Different applications might have different testing environments, also it might make sense to enable the cache for testing in some cases, to replicate bugs. My suggestion would be to turn off the cache in the testing process as follows:

php artisan lada-cache:disable
php artisan lada-cache:enable

Open to other ideas as well.

@zgetro
Copy link
Author

zgetro commented Nov 12, 2024

Unfortunately it is not working, here are my steps to reproduce it.
service redis-server stop and run .\vendor\bin\phpunit

17  forward_static_call_array()
      C:\Users\zgetro\Code\x-portal\vendor\spiritix\lada-cache\src\Spiritix\LadaCache\Redis.php:62

  18  Spiritix\LadaCache\Redis::__call("exists")
      C:\Users\zgetro\Code\x-portal\vendor\spiritix\lada-cache\src\Spiritix\LadaCache\Invalidator.php:78

  19  Spiritix\LadaCache\Invalidator::getHashes()
      C:\Users\zgetro\Code\x-portal\vendor\spiritix\lada-cache\src\Spiritix\LadaCache\Invalidator.php:51

  20  Spiritix\LadaCache\Invalidator::invalidate()
      C:\Users\zgetro\Code\x-portal\vendor\spiritix\lada-cache\src\Spiritix\LadaCache\QueryHandler.php:185

  21  Spiritix\LadaCache\QueryHandler::invalidateQuery("insert")
      C:\Users\zgetro\Code\x-portal\vendor\spiritix\lada-cache\src\Spiritix\LadaCache\Database\QueryBuilder.php:130

  22  Spiritix\LadaCache\Database\QueryBuilder::insertGetId("id")
      C:\Users\zgetro\Code\x-portal\vendor\laravel\framework\src\Illuminate\Database\Eloquent\Builder.php:1353 

if you think 🤔 hardcode behaviour is not good then we should check that in env like you suggested.

    /**
     * Get a new query builder instance for the connection.
     *
     * @return QueryBuilder
     */
    protected function newBaseQueryBuilder()
    {

        if (config('lada-cache.enabled') === false) {
            return parent::newBaseQueryBuilder(); // Use default Laravel query builder
        }
         $conn = $this->getConnection();
        $grammar = $conn->getQueryGrammar();

        return new QueryBuilder(
            $conn,
            $grammar,
            $conn->getPostProcessor(),
            app()->make('lada.handler'),
            $this
        );
    }

as i drill down after your comments and found only this place need patch.

@spiritix
Copy link
Owner

Agreed that's not ideal. The library should be disabled entirely when the ENV variable is set to false.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants