improve performance of photo upload page

This commit is contained in:
friendica 2012-11-25 19:34:54 -08:00
parent 15ede093cf
commit 5d904a9fa8
5 changed files with 21 additions and 13 deletions

View file

@ -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', "<br />\r\n" );
define ( 'ATOM_TIME', 'Y-m-d\TH:i:s\Z' );

View file

@ -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;

View file

@ -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),

View file

@ -1027,19 +1027,15 @@ function photos_content(&$a) {
$default_upload = '<input id="photos-upload-choose" type="file" name="userfile" /> <div class="photos-upload-submit-wrapper" >
<input type="submit" name="submit" value="' . t('Submit') . '" id="photos-upload-submit" /> </div>';
$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');

View file

@ -1,6 +1,6 @@
<?php
define( 'UPDATE_VERSION' , 1156 );
define( 'UPDATE_VERSION' , 1157 );
/**
*
@ -1362,3 +1362,10 @@ function update_1155() {
return UPDATE_FAILED;
}
function update_1156() {
$r = q("ALTER TABLE `photo` ADD `datasize` INT UNSIGNED NOT NULL DEFAULT '0' AFTER `width` ,
ADD INDEX ( `datasize` ) ");
if(!$r) return UPDATE_FAILED;
return UPDATE_SUCCESS;
}