Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/Service/OpenAiAPIService.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function __construct(
}

/**
* @param string $userId
* @param string $userId It can be an empty string
* @param int $type
* @param int $usage
* @throws Exception If there is an error creating the quota usage.
Expand Down
11 changes: 8 additions & 3 deletions lib/Service/QuotaRuleService.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,26 @@ public function __construct(
private LoggerInterface $logger,
) {
}

/**
* Returns the quota rule for the given user
*
* @param int $quotaType
* @param string $userId
* @param string $userId It can be an empty string
* @return array
*/
public function getRule(int $quotaType, string $userId) {
$cache = $this->cacheFactory->createDistributed(Application::APP_ID);
$cacheKey = Application::QUOTA_RULES_CACHE_PREFIX . $quotaType . '-' . $userId;
$rule = $cache->get($cacheKey);
if ($rule === null) {
$user = $this->userManager->get($userId);
$groups = $this->groupManager->getUserGroupIds($user);
try {
$user = $this->userManager->get($userId);
if ($user === null) {
// re-use the db exception for not found users
throw new DoesNotExistException('User not found: ' . $userId);
}
$groups = $this->groupManager->getUserGroupIds($user);
$rule = $this->quotaRuleMapper->getRule($quotaType, $userId, $groups)->jsonSerialize();
} catch (DoesNotExistException|MultipleObjectsReturnedException) {
$rule = [
Expand Down
Loading