Also cache the resource type because it is part of the identifier
Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
parent
066238a990
commit
411350540d
|
@ -85,6 +85,11 @@ class Version16000Date20190207141427 extends SimpleMigrationStep {
|
|||
'notnull' => false,
|
||||
'default' => 0,
|
||||
]);
|
||||
$table->addColumn('resource_type', Type::STRING, [
|
||||
'notnull' => false,
|
||||
'length' => 64,
|
||||
'default' => '',
|
||||
]);
|
||||
$table->addColumn('resource_id', Type::STRING, [
|
||||
'notnull' => false,
|
||||
'length' => 64,
|
||||
|
@ -95,8 +100,8 @@ class Version16000Date20190207141427 extends SimpleMigrationStep {
|
|||
'default' => 0,
|
||||
]);
|
||||
|
||||
$table->addUniqueIndex(['user_id', 'collection_id', 'resource_id'], 'collres_unique_user');
|
||||
$table->addIndex(['user_id', 'resource_id'], 'collres_user_res');
|
||||
$table->addUniqueIndex(['user_id', 'collection_id', 'resource_type', 'resource_id'], 'collres_unique_user');
|
||||
$table->addIndex(['user_id', 'resource_type', 'resource_id'], 'collres_user_res');
|
||||
$table->addIndex(['user_id', 'collection_id'], 'collres_user_coll');
|
||||
}
|
||||
|
||||
|
|
|
@ -200,6 +200,7 @@ class Manager implements IManager {
|
|||
'r', self::TABLE_ACCESS_CACHE, 'a',
|
||||
$query->expr()->andX(
|
||||
$query->expr()->eq('r.resource_id', 'a.resource_id'),
|
||||
$query->expr()->eq('r.resource_type', 'a.resource_type'),
|
||||
$query->expr()->eq('a.user_id', $query->createNamedParameter($userId, IQueryBuilder::PARAM_STR))
|
||||
)
|
||||
)
|
||||
|
@ -237,6 +238,7 @@ class Manager implements IManager {
|
|||
'r', self::TABLE_ACCESS_CACHE, 'a',
|
||||
$query->expr()->andX(
|
||||
$query->expr()->eq('r.resource_id', 'a.resource_id'),
|
||||
$query->expr()->eq('r.resource_type', 'a.resource_type'),
|
||||
$query->expr()->eq('a.user_id', $query->createNamedParameter($userId, IQueryBuilder::PARAM_STR))
|
||||
)
|
||||
)
|
||||
|
@ -362,6 +364,7 @@ class Manager implements IManager {
|
|||
$query->select('access')
|
||||
->from(self::TABLE_ACCESS_CACHE)
|
||||
->where($query->expr()->eq('resource_id', $query->createNamedParameter($resource->getId(), IQueryBuilder::PARAM_STR)))
|
||||
->andWhere($query->expr()->eq('resource_type', $query->createNamedParameter($resource->getType(), IQueryBuilder::PARAM_STR)))
|
||||
->andWhere($query->expr()->eq('user_id', $query->createNamedParameter($userId, IQueryBuilder::PARAM_STR)))
|
||||
->setMaxResults(1);
|
||||
|
||||
|
@ -403,6 +406,7 @@ class Manager implements IManager {
|
|||
->values([
|
||||
'user_id' => $query->createNamedParameter($userId),
|
||||
'resource_id' => $query->createNamedParameter($resource->getId()),
|
||||
'resource_type' => $query->createNamedParameter($resource->getType()),
|
||||
'access' => $query->createNamedParameter($access),
|
||||
]);
|
||||
try {
|
||||
|
@ -440,7 +444,8 @@ class Manager implements IManager {
|
|||
$query = $this->connection->getQueryBuilder();
|
||||
|
||||
$query->delete(self::TABLE_ACCESS_CACHE)
|
||||
->where($query->expr()->eq('resource_id', $query->createNamedParameter($resource->getId())));
|
||||
->where($query->expr()->eq('resource_id', $query->createNamedParameter($resource->getId())))
|
||||
->andWhere($query->expr()->eq('resource_type', $query->createNamedParameter($resource->getType(), IQueryBuilder::PARAM_STR)));
|
||||
$query->execute();
|
||||
|
||||
foreach ($resource->getCollections() as $collection) {
|
||||
|
@ -456,6 +461,14 @@ class Manager implements IManager {
|
|||
$query->execute();
|
||||
}
|
||||
|
||||
public function invalidateAccessCacheForProvider(IProvider $provider): void {
|
||||
$query = $this->connection->getQueryBuilder();
|
||||
|
||||
$query->delete(self::TABLE_ACCESS_CACHE)
|
||||
->where($query->expr()->eq('resource_type', $query->createNamedParameter($provider->getType(), IQueryBuilder::PARAM_STR)));
|
||||
$query->execute();
|
||||
}
|
||||
|
||||
public function invalidateAccessCacheForResourceByUser(IResource $resource, ?IUser $user): void {
|
||||
$query = $this->connection->getQueryBuilder();
|
||||
$userId = $user instanceof IUser ? $user->getUID() : '';
|
||||
|
@ -480,6 +493,16 @@ class Manager implements IManager {
|
|||
$query->execute();
|
||||
}
|
||||
|
||||
public function invalidateAccessCacheForProviderByUser(IProvider $provider, ?IUser $user): void {
|
||||
$query = $this->connection->getQueryBuilder();
|
||||
$userId = $user instanceof IUser ? $user->getUID() : '';
|
||||
|
||||
$query->delete(self::TABLE_ACCESS_CACHE)
|
||||
->where($query->expr()->eq('resource_type', $query->createNamedParameter($provider->getType(), IQueryBuilder::PARAM_STR)))
|
||||
->andWhere($query->expr()->eq('user_id', $query->createNamedParameter($userId)));
|
||||
$query->execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param IProvider $provider
|
||||
*/
|
||||
|
|
|
@ -82,6 +82,19 @@ interface IManager extends IProvider {
|
|||
*/
|
||||
public function invalidateAccessCacheForResourceByUser(IResource $resource, ?IUser $user): void;
|
||||
|
||||
/**
|
||||
* @param IProvider $provider
|
||||
* @since 16.0.0
|
||||
*/
|
||||
public function invalidateAccessCacheForProvider(IProvider $provider): void;
|
||||
|
||||
/**
|
||||
* @param IProvider $provider
|
||||
* @param IUser|null $user
|
||||
* @since 16.0.0
|
||||
*/
|
||||
public function invalidateAccessCacheForProviderByUser(IProvider $provider, ?IUser $user): void;
|
||||
|
||||
/**
|
||||
* @param string $type
|
||||
* @param string $id
|
||||
|
|
Loading…
Reference in New Issue