From 5d904a9fa8b383c7aa736993aa07b7d4d74c5fce Mon Sep 17 00:00:00 2001 From: friendica Date: Sun, 25 Nov 2012 19:34:54 -0800 Subject: [PATCH] improve performance of photo upload page --- boot.php | 2 +- database.sql | 2 ++ include/Photo.php | 7 +++++-- mod/photos.php | 14 +++++--------- update.php | 9 ++++++++- 5 files changed, 21 insertions(+), 13 deletions(-) diff --git a/boot.php b/boot.php index 8c3cf7b273..1809df966c 100644 --- a/boot.php +++ b/boot.php @@ -14,7 +14,7 @@ require_once('include/features.php'); define ( 'FRIENDICA_PLATFORM', 'Friendica'); define ( 'FRIENDICA_VERSION', '3.0.1538' ); define ( 'DFRN_PROTOCOL_VERSION', '2.23' ); -define ( 'DB_UPDATE_VERSION', 1156 ); +define ( 'DB_UPDATE_VERSION', 1157 ); define ( 'EOL', "
\r\n" ); define ( 'ATOM_TIME', 'Y-m-d\TH:i:s\Z' ); diff --git a/database.sql b/database.sql index 0f82616f7b..369637fe60 100644 --- a/database.sql +++ b/database.sql @@ -777,6 +777,7 @@ CREATE TABLE IF NOT EXISTS `photo` ( `type` CHAR(128) NOT NULL DEFAULT 'image/jpeg', `height` smallint(6) NOT NULL, `width` smallint(6) NOT NULL, + `datasize` int(10) unsigned NOT NULL DEFAULT '0', `data` mediumblob NOT NULL, `scale` tinyint(3) NOT NULL, `profile` tinyint(1) NOT NULL DEFAULT '0', @@ -789,6 +790,7 @@ CREATE TABLE IF NOT EXISTS `photo` ( KEY `resource-id` (`resource-id`), KEY `album` (`album`), KEY `scale` (`scale`), + KEY `datasize` (`datasize`), KEY `profile` (`profile`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; diff --git a/include/Photo.php b/include/Photo.php index 8fd581977d..69b08f6291 100644 --- a/include/Photo.php +++ b/include/Photo.php @@ -584,6 +584,7 @@ class Photo { `album` = '%s', `height` = %d, `width` = %d, + `datasize` = %d, `data` = '%s', `scale` = %d, `profile` = %d, @@ -604,6 +605,7 @@ class Photo { dbesc($album), intval($this->getHeight()), intval($this->getWidth()), + dbesc(strlen($this->imageString())), dbesc($this->imageString()), intval($scale), intval($profile), @@ -616,8 +618,8 @@ class Photo { } else { $r = q("INSERT INTO `photo` - ( `uid`, `contact-id`, `guid`, `resource-id`, `created`, `edited`, `filename`, type, `album`, `height`, `width`, `data`, `scale`, `profile`, `allow_cid`, `allow_gid`, `deny_cid`, `deny_gid` ) - VALUES ( %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, '%s', %d, %d, '%s', '%s', '%s', '%s' )", + ( `uid`, `contact-id`, `guid`, `resource-id`, `created`, `edited`, `filename`, type, `album`, `height`, `width`, `datasize`, `data`, `scale`, `profile`, `allow_cid`, `allow_gid`, `deny_cid`, `deny_gid` ) + VALUES ( %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, %d, '%s', %d, %d, '%s', '%s', '%s', '%s' )", intval($uid), intval($cid), dbesc($guid), @@ -629,6 +631,7 @@ class Photo { dbesc($album), intval($this->getHeight()), intval($this->getWidth()), + dbesc(strlen($this->imageString())), dbesc($this->imageString()), intval($scale), intval($profile), diff --git a/mod/photos.php b/mod/photos.php index 08dc0e0fc5..efccb0e10a 100644 --- a/mod/photos.php +++ b/mod/photos.php @@ -1027,19 +1027,15 @@ function photos_content(&$a) { $default_upload = '
'; - - $r = q("select sum(octet_length(data)) as total from photo where uid = %d and scale = 0 and album != 'Contact Photos' ", - intval($a->data['user']['uid']) - ); - - + $usage_message = ''; $limit = service_class_fetch($a->data['user']['uid'],'photo_upload_limit'); if($limit !== false) { + + $r = q("select sum(datasize) as total from photo where uid = %d and scale = 0 and album != 'Contact Photos' ", + intval($a->data['user']['uid']) + ); $usage_message = sprintf( t("You have used %1$.2f Mbytes of %2$.2f Mbytes photo storage."), $r[0]['total'] / 1024000, $limit / 1024000 ); } - else { - $usage_message = sprintf( t('You have used %1$.2f Mbytes of photo storage.'), $r[0]['total'] / 1024000 ); - } $tpl = get_markup_template('photos_upload.tpl'); diff --git a/update.php b/update.php index 3d3eec6f97..b29afdb741 100644 --- a/update.php +++ b/update.php @@ -1,6 +1,6 @@