diff --git a/lib/Db/ExtMapper.php b/lib/Db/ExtMapper.php
index 20866747fe5c9c4714ac3d317ce28a01b01fbd72..c06cb3f69cc1076e92e1695a16442d224e4d68c6 100644
--- a/lib/Db/ExtMapper.php
+++ b/lib/Db/ExtMapper.php
@@ -9,6 +9,7 @@ use OCP\AppFramework\Db\{
     MultipleObjectsReturnedException,
     QBMapper
 };
+use OCA\SccuotNC\Db\OC\AccountsMapper;
 use OCP\DB\QueryBuilder\IQueryBuilder;
 use OCP\IDBConnection;
 
@@ -157,4 +158,5 @@ abstract class ExtMapper extends QBMapper {
 		}
 		return $offset;
 	}
+
 }
diff --git a/lib/Db/OC/AccountsMapper.php b/lib/Db/OC/AccountsMapper.php
index 2383f4252f782b78f154b557e037266bbf694310..f7ef7ecc79af2f72b2e2aa1d8d3fb466b6d9f296 100644
--- a/lib/Db/OC/AccountsMapper.php
+++ b/lib/Db/OC/AccountsMapper.php
@@ -9,6 +9,7 @@ use OCP\DB\Exception;
 use OCP\IDBConnection;
 use OCP\DB\QueryBuilder\IQueryBuilder;
 use OCA\SccuotNC\Service\ConfigService;
+use PDO;
 
 class AccountsMapper extends ExtMapper {
     const PREFERENCES_TABLE = 'preferences';
@@ -20,8 +21,19 @@ class AccountsMapper extends ExtMapper {
     }
 
 	public function queryTotalCount(string $state): int {
-		$users = $this->configService->config()->getUsersForUserValue('core', 'enabled', $state);
-		return count($users);
+		$users = $this->configService->config()->getUsersForUserValue('core', 'enabled', 'false');
+		if ($state === 'false') {
+			return count($users);
+		}
+		$qb = $this->db->getQueryBuilder();
+		$qb->selectAlias($qb->createFunction('COUNT(uid)'), 'c')
+			->from('accounts');
+
+		$stmt = $qb->execute();
+		$result = $stmt->fetch();
+		$stmt->closeCursor();
+
+		return $result['c'] - count($users);
 	}
 
 	/**
@@ -45,7 +57,7 @@ class AccountsMapper extends ExtMapper {
 	 * @throws \Exception
 	 */
 	public function queryUserStorages(): array {
-		$activeUsers = $this->configService->config()->getUsersForUserValue('core', 'enabled', 'true');
+		$activeUsers = $this->getActiveUsers();
 		$data = [
 			'storages' => []
 		];
@@ -76,7 +88,7 @@ class AccountsMapper extends ExtMapper {
 	}
 
 	public function queryUserQuotas($defaultQuotas) {
-		$activeUsers = $this->configService->config()->getUsersForUserValue('core', 'enabled', 'true');
+		$activeUsers = $this->getActiveUsers();
 		$data = [
 			'defaultQuotas' => $defaultQuotas,
 			'quotas' => []
@@ -121,4 +133,18 @@ class AccountsMapper extends ExtMapper {
 		return false;
 	}
 
+	protected function getActiveUsers(): array {
+		$deactivatedUsers = $this->configService->config()->getUsersForUserValue('core', 'enabled', 'false');
+		$qb = $this->db->getQueryBuilder();
+		$qb->select('uid')
+			->from('accounts');
+
+		$stmt = $qb->execute();
+		$result = $stmt->fetchAll(PDO::FETCH_COLUMN);
+		$stmt->closeCursor();
+
+		$activeUsers = array_diff($result, $deactivatedUsers);
+		return $activeUsers;
+	}
+
 }
diff --git a/lib/Db/OC/FilecacheMapper.php b/lib/Db/OC/FilecacheMapper.php
index a7d9080ec64d47e4d26f2278e6b4a66d30f933a7..72da56919dcf58d56fb21f5a667464776f2dfd2a 100644
--- a/lib/Db/OC/FilecacheMapper.php
+++ b/lib/Db/OC/FilecacheMapper.php
@@ -141,7 +141,15 @@ class FilecacheMapper extends ExtMapper {
 			$qb->selectDistinct('userid')
 				->from(AccountsMapper::PREFERENCES_TABLE)
 				->where($qb->expr()->eq('configkey', $qb->expr()->literal('enabled')))
-				->andWhere($qb->expr()->eq('configvalue', $qb->expr()->literal($this->accountsState)));
+				->andWhere($qb->expr()->eq('configvalue', $qb->expr()->literal('false')));
+
+			$query->andWhere($query->expr()->eq('configkey', $query->expr()->literal('%quota%')));
+			if ($this->accountsState == 'true') {
+				$query->andWhere($query->expr()->notIn('p.userid', $query->createFunction($qb->getSQL())));
+			} else {
+				$query->andWhere($query->expr()->in('p.userid', $query->createFunction($qb->getSQL())));
+			}
+
 		}
 	}