Issue #118 wanted better TOR support, now Avatar URLs are not stored

There was no reason to store the generated Avatar URLs because it's so
cheap to generate them on the fly.
This commit is contained in:
Mikael Nordfeldth 2016-01-06 16:14:26 +01:00
parent 7b2036a4b5
commit 1a1e44cdfd
4 changed files with 4 additions and 49 deletions

View File

@ -1,14 +1,13 @@
<?php <?php
if (!defined('GNUSOCIAL')) { exit(1); }
/** /**
* Table Definition for avatar * Table Definition for avatar
*/ */
require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
class Avatar extends Managed_DataObject class Avatar extends Managed_DataObject
{ {
###START_AUTOCODE
/* the code below is auto generated do not remove the above tag */
public $__table = 'avatar'; // table name public $__table = 'avatar'; // table name
public $profile_id; // int(4) primary_key not_null public $profile_id; // int(4) primary_key not_null
public $original; // tinyint(1) public $original; // tinyint(1)
@ -16,13 +15,9 @@ class Avatar extends Managed_DataObject
public $height; // int(4) primary_key not_null public $height; // int(4) primary_key not_null
public $mediatype; // varchar(32) not_null public $mediatype; // varchar(32) not_null
public $filename; // varchar(191) not 255 because utf8mb4 takes more space public $filename; // varchar(191) not 255 because utf8mb4 takes more space
public $url; // varchar(191) unique_key not 255 because utf8mb4 takes more space
public $created; // datetime() not_null public $created; // datetime() not_null
public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP
/* the code above is auto generated do not remove the tag below */
###END_AUTOCODE
public static function schemaDef() public static function schemaDef()
{ {
return array( return array(
@ -33,7 +28,6 @@ class Avatar extends Managed_DataObject
'height' => array('type' => 'int', 'not null' => true, 'description' => 'image height'), 'height' => array('type' => 'int', 'not null' => true, 'description' => 'image height'),
'mediatype' => array('type' => 'varchar', 'length' => 32, 'not null' => true, 'description' => 'file type'), 'mediatype' => array('type' => 'varchar', 'length' => 32, 'not null' => true, 'description' => 'file type'),
'filename' => array('type' => 'varchar', 'length' => 191, 'description' => 'local filename, if local'), 'filename' => array('type' => 'varchar', 'length' => 191, 'description' => 'local filename, if local'),
'url' => array('type' => 'text', 'description' => 'avatar location, not indexed - do not use in WHERE statement'),
'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'), 'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'), 'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),
), ),
@ -211,12 +205,7 @@ class Avatar extends Managed_DataObject
function displayUrl() function displayUrl()
{ {
$server = common_config('avatar', 'server');
if ($server && !empty($this->filename)) {
return Avatar::url($this->filename); return Avatar::url($this->filename);
} else {
return $this->url;
}
} }
static function urlByProfile(Profile $target, $width=null, $height=null) { static function urlByProfile(Profile $target, $width=null, $height=null) {
@ -256,7 +245,6 @@ class Avatar extends Managed_DataObject
$scaled->original = false; $scaled->original = false;
$scaled->width = $width; $scaled->width = $width;
$scaled->height = $height; $scaled->height = $height;
$scaled->url = Avatar::url($filename);
$scaled->filename = $filename; $scaled->filename = $filename;
$scaled->created = common_sql_now(); $scaled->created = common_sql_now();

View File

@ -175,7 +175,6 @@ class Profile extends Managed_DataObject
$avatar->mediatype = image_type_to_mime_type($imagefile->type); $avatar->mediatype = image_type_to_mime_type($imagefile->type);
$avatar->filename = $filename; $avatar->filename = $filename;
$avatar->original = true; $avatar->original = true;
$avatar->url = Avatar::url($filename);
$avatar->created = common_sql_now(); $avatar->created = common_sql_now();
// XXX: start a transaction here // XXX: start a transaction here

View File

@ -366,7 +366,6 @@ class TwitterImport
$avatar->original = 1; // this is an original/"uploaded" avatar $avatar->original = 1; // this is an original/"uploaded" avatar
$avatar->mediatype = $mediatype; $avatar->mediatype = $mediatype;
$avatar->filename = $filename; $avatar->filename = $filename;
$avatar->url = Avatar::url($filename);
$avatar->width = $this->avatarsize; $avatar->width = $this->avatarsize;
$avatar->height = $this->avatarsize; $avatar->height = $this->avatarsize;

View File

@ -51,7 +51,6 @@ function updateUserUrls()
$profile = $user->getProfile(); $profile = $user->getProfile();
updateProfileUrl($profile); updateProfileUrl($profile);
updateAvatarUrls($profile);
} catch (Exception $e) { } catch (Exception $e) {
echo "Error updating URLs: " . $e->getMessage(); echo "Error updating URLs: " . $e->getMessage();
} }
@ -67,36 +66,6 @@ function updateProfileUrl($profile)
$profile->update($orig); $profile->update($orig);
} }
function updateAvatarUrls($profile)
{
$avatar = new Avatar();
$avatar->profile_id = $profile->id;
if ($avatar->find()) {
while ($avatar->fetch()) {
$orig_url = $avatar->url;
$avatar->url = Avatar::url($avatar->filename);
if ($avatar->url != $orig_url) {
$sql =
"UPDATE avatar SET url = '" . $avatar->url . "' ".
"WHERE profile_id = " . $avatar->profile_id . " ".
"AND width = " . $avatar->width . " " .
"AND height = " . $avatar->height . " ";
if ($avatar->original) {
$sql .= "AND original = 1 ";
}
if (!$avatar->query($sql)) {
throw new Exception("Can't update avatar for user " . $profile->nickname . ".");
} else {
$touched = true;
}
}
}
}
}
function updateGroupUrls() function updateGroupUrls()
{ {
printfnq("Updating group URLs...\n"); printfnq("Updating group URLs...\n");