Giter Club home page Giter Club logo

Comments (12)

drbyte avatar drbyte commented on May 28, 2024 1

Okay. I think what we'll do is, in this package add the reset for team ID and wildcard permissions.

And then for the parts you need in your own app, you can register a listener on Octane's OperationTerminated for those things unique to your own requirements.

from laravel-permission.

parallels999 avatar parallels999 commented on May 28, 2024 1
public function clearPermissionsCollection(): void 
{ 
   $this->permissions = null; 
   $this->wildcardPermissionsIndex = []; 
} 

from laravel-permission.

drbyte avatar drbyte commented on May 28, 2024

I've not yet worked with Octane for a production app, so my "testing" of things like this has been limited. But would like to dig deeper.

Do you mind providing a demo app, replicating the features and symptoms you describe, which we can use for exploring and debugging further?

from laravel-permission.

Cluster2a avatar Cluster2a commented on May 28, 2024

@drbyte, as the current code base relies on many services (realtime events, after role switch), it would be easier to create a simple example with a single controller and a few endpoints to change a role.

I think the best way to test & debug would be an example which runs on a local micrk8s instance. But I would need some time for the example.

from laravel-permission.

parallels999 avatar parallels999 commented on May 28, 2024

$event->sandbox->make(PermissionRegistrar::class)->forgetCachedPermissions();

that removes the cache in each request and create a new one again, if you are going to do that it is better to use array in the cache store configuration, this way you will use less resources

'store' => 'default',

What do you use for the cache? redis?

from laravel-permission.

Cluster2a avatar Cluster2a commented on May 28, 2024

What do you use for the cache? redis?

I am using redis. I tried a different approach, since I don't want to clear the entire cache:
image

This also works.

@drbyte, fyi.

from laravel-permission.

parallels999 avatar parallels999 commented on May 28, 2024

Make a PR

$dispatcher->listen(function (\Laravel\Octane\Events\OperationTerminated $event) {
// @phpstan-ignore-next-line
$event->sandbox->make(PermissionRegistrar::class)->clearPermissionsCollection();
});

from laravel-permission.

drbyte avatar drbyte commented on May 28, 2024

I'm not sure it's safe to hard-code any resets to instance of User because we can't guarantee that.
Perhaps instance of Authenticatable contract.

But is the call to $user->resetPermissionDate() critical?

from laravel-permission.

drbyte avatar drbyte commented on May 28, 2024

I agree with the call to setPermissionsTeamId(null) and forgetWildcardPermissionIndex().

from laravel-permission.

Cluster2a avatar Cluster2a commented on May 28, 2024

@drbyte, we are using some custom permission cache on the user - this part can be ignored. Most important seems to be, that the wildcard cache is beeing deleted.

from laravel-permission.

drbyte avatar drbyte commented on May 28, 2024

Hmmm ... I forgot: we already have the reset for team ID since 6.1.0

from laravel-permission.

drbyte avatar drbyte commented on May 28, 2024

So ... @erikn69 @parallels999 I'm curious your opinion on whether we should add an Octane-specific reset for forgetWildcardPermissionIndex(), or simply combine forgetWildcardPermissionIndex() into clearPermissionsCollection()

/**
* Clear already-loaded permissions collection.
* This is only intended to be called by the PermissionServiceProvider on boot,
* so that long-running instances like Octane or Swoole don't keep old data in memory.
*/
public function clearPermissionsCollection(): void
{
$this->permissions = null;
}

Noting:

/**
* Flush the cache.
*/
public function forgetCachedPermissions()
{
$this->permissions = null;
$this->forgetWildcardPermissionIndex();
return $this->cache->forget($this->cacheKey);
}
public function forgetWildcardPermissionIndex(?Model $record = null): void
{
if ($record) {
unset($this->wildcardPermissionsIndex[get_class($record)][$record->getKey()]);
return;
}
$this->wildcardPermissionsIndex = [];
}

from laravel-permission.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.