Kaynağa Gözat

Affiche la taille de la base de données

Alexandre Alapetite 12 yıl önce
ebeveyn
işleme
b40783e888

+ 1 - 0
app/controllers/configureController.php

@@ -265,6 +265,7 @@ class configureController extends ActionController {
 
 		$entryDAO = new EntryDAO ();
 		$this->view->nb_total = $entryDAO->count ();
+		$this->view->size_total = $entryDAO->size ();
 	}
 
 	public function sharingAction () {

+ 2 - 2
app/i18n/en.php

@@ -132,7 +132,7 @@ return array (
 	'feed_description'		=> 'Description',
 	'website_url'			=> 'Website URL',
 	'feed_url'			=> 'Feed URL',
-	'number_articles'		=> 'Number of articles',
+	'articles'		=> 'articles',
 	'keep_history'			=> 'Keep history?',
 	'categorize'			=> 'Store in a category',
 	'advanced'			=> 'Advanced',
@@ -182,7 +182,7 @@ return array (
 	'share'				=> 'Share',
 	'by_email'			=> 'By email',
 	'optimize_bdd'			=> 'Optimize database',
-	'optimize_todo_sometimes'	=> 'To do occasionally to reduce size of database',
+	'optimize_todo_sometimes'	=> 'To do occasionally to improve performance',
 	'theme'				=> 'Theme',
 	'more_information'		=> 'More information',
 	'activate_sharing'		=> 'Activate sharing',

+ 2 - 2
app/i18n/fr.php

@@ -132,7 +132,7 @@ return array (
 	'feed_description'		=> 'Description',
 	'website_url'			=> 'URL du site',
 	'feed_url'			=> 'URL du flux',
-	'number_articles'		=> 'Nombre d’articles',
+	'articles'		=> 'articles',
 	'keep_history'			=> 'Garder l’historique ?',
 	'categorize'			=> 'Ranger dans une catégorie',
 	'advanced'			=> 'Avancé',
@@ -182,7 +182,7 @@ return array (
 	'share'				=> 'Partager',
 	'by_email'			=> 'Par courriel',
 	'optimize_bdd'			=> 'Optimiser la base de données',
-	'optimize_todo_sometimes'	=> 'À faire de temps en temps pour réduire la taille de la BDD',
+	'optimize_todo_sometimes'	=> 'À faire de temps en temps pour améliorer les performances',
 	'theme'				=> 'Thème',
 	'more_information'		=> 'Plus d’informations',
 	'activate_sharing'		=> 'Activer le partage',

+ 1 - 1
app/views/configure/display.phtml

@@ -196,7 +196,7 @@
 		<div class="form-group">
 			<label class="group-name"></label>
 			<div class="group-controls">
-				<p><?php echo Translate::t('number_articles') ?> <code><?php echo $this->nb_total; ?></code></p>
+				<p><?php echo $this->nb_total; ?> <?php echo Translate::t('articles') ?>, <?php echo formatBytes($this->size_total); ?>.</p>
 				<p><a class="btn" href="<?php echo _url('entry', 'optimize'); ?>">
 					<?php echo Translate::t('optimize_bdd'); ?>
 				</a></p>

+ 15 - 0
lib/lib_rss.php

@@ -47,6 +47,21 @@ function small_hash ($txt) {
 	return strtr ($t, '+/', '-_');
 }
 
+function formatBytes($bytes, $precision = 2, $system = 'IEC') {
+	if ($system === 'IEC') {
+		$base = 1024;
+		$units = array('B', 'KiB', 'MiB', 'GiB', 'TiB');
+	} elseif ($system === 'SI') {
+		$base = 1000;
+		$units = array('B', 'KB', 'MB', 'GB', 'TB');
+	}
+	$bytes = max(intval($bytes), 0);
+	$pow = $bytes === 0 ? 0 : floor(log($bytes) / log($base));
+	$pow = min($pow, count($units) - 1);
+	$bytes /= pow($base, $pow);
+	return round($bytes, $precision) . ' ' . $units[$pow];
+}
+
 function timestamptodate ($t, $hour = true) {
 	$month = Translate::t (date('M', $t));
 	if ($hour) {

+ 10 - 0
lib/minz/dao/Model_pdo.php

@@ -80,6 +80,16 @@ class Model_pdo {
 	public function rollBack() {
 		$this->bd->rollBack();
 	}
+
+	public function size() {
+		$db = Configuration::dataBase ();
+		$sql = 'SELECT SUM(data_length + index_length) FROM information_schema.TABLES WHERE table_schema = ?';
+		$stm = $this->bd->prepare ($sql);
+		$values = array ($db['base']);
+		$stm->execute ($values);
+		$res = $stm->fetchAll(PDO::FETCH_COLUMN, 0);
+		return $res[0];
+	}
 }
 
 class FreshPDO extends PDO {