Overview
Comment:Cache quota as it may make things slow
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | dev
Files: files | file ages | folders
SHA3-256: c0f86221c085105e2a2d742f0d91714f331fafcf9d5e2e55e53d4a41bc885d94
User & Date: bohwaz on 2021-03-30 21:58:33
Other Links: branch diff | manifest | tags
Context
2021-03-30
22:12
Fix bug on session when upgrading, bump to beta1 check-in: 1eada42387 user: bohwaz tags: dev, 1.1.0-beta1
21:58
Cache quota as it may make things slow check-in: c0f86221c0 user: bohwaz tags: dev
21:45
Fix collation check-in: 9ecbcbce5c user: bohwaz tags: dev
Changes

Modified src/include/lib/Garradin/Files/Files.php from [49b0b5706b] to [975d9a5fb6].

217
218
219
220
221
222
223
224
225

226

227


228




229
230
231
232
233
234
235
236
237
238
239
240
241
242
243

244
245
246
247
	}

	static public function getQuota(): int
	{
		return FILE_STORAGE_QUOTA ?? self::callStorage('getQuota');
	}

	static public function getUsedQuota(): int
	{

		return self::callStorage('getTotalSize');

	}







	static public function getRemainingQuota(): int
	{
		if (FILE_STORAGE_QUOTA !== null) {
			return FILE_STORAGE_QUOTA - self::getUsedQuota();
		}

		return self::callStorage('getRemainingQuota');
	}

	static public function checkQuota(int $size = 0): void
	{
		$quota = self::getQuota();
		$used = self::callStorage('getTotalSize');

		if (($used + $size) >= $quota) {

			throw new ValidationException('L\'espace disque est insuffisant pour réaliser cette opération');
		}
	}
}







|

>
|
>
|
>
>
|
>
>
>
>
|


|







|
<

<
>




217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248

249

250
251
252
253
254
	}

	static public function getQuota(): int
	{
		return FILE_STORAGE_QUOTA ?? self::callStorage('getQuota');
	}

	static public function getUsedQuota(bool $force_refresh = false): int
	{
		if ($force_refresh || Static_Cache::expired('used_quota', 3600)) {
			$quota = self::callStorage('getTotalSize');
			Static_Cache::store('used_quota', $quota);
		}
		else {
			$quota = (int) Static_Cache::get('used_quota');
		}

		return $quota;
	}

	static public function getRemainingQuota(bool $force_refresh = false): int
	{
		if (FILE_STORAGE_QUOTA !== null) {
			return FILE_STORAGE_QUOTA - self::getUsedQuota($force_refresh);
		}

		return self::callStorage('getRemainingQuota');
	}

	static public function checkQuota(int $size = 0): void
	{
		$remaining = self::getRemainingQuota(true);



		if (($remaining - $size) < 0) {
			throw new ValidationException('L\'espace disque est insuffisant pour réaliser cette opération');
		}
	}
}

Modified src/include/lib/Garradin/Files/Storage/SQLite.php from [4526537084] to [1733617c6f].

187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
		}

		return true;
	}

	static public function getTotalSize(): int
	{
		return (int) DB::getInstance()->firstColumn('SELECT SUM(LENGTH(content)) FROM files_contents;');
	}

	/**
	 * @see https://www.crazyws.fr/dev/fonctions-php/fonction-disk-free-space-et-disk-total-space-pour-ovh-2JMH9.html
	 * @see https://github.com/jdel/sspks/commit/a890e347f32e9e3e50a0dd82398947633872bf38
	 */
	static public function getQuota(): int







|







187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
		}

		return true;
	}

	static public function getTotalSize(): int
	{
		return (int) DB::getInstance()->firstColumn('SELECT SUM(size) FROM files;');
	}

	/**
	 * @see https://www.crazyws.fr/dev/fonctions-php/fonction-disk-free-space-et-disk-total-space-pour-ovh-2JMH9.html
	 * @see https://github.com/jdel/sspks/commit/a890e347f32e9e3e50a0dd82398947633872bf38
	 */
	static public function getQuota(): int