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
if (!defined('GNUSOCIAL')) { exit(1); }
/**
* Table Definition for avatar
*/
require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
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 $profile_id; // int(4) primary_key not_null
public $original; // tinyint(1)
@ -16,12 +15,8 @@ class Avatar extends Managed_DataObject
public $height; // int(4) primary_key not_null
public $mediatype; // varchar(32) not_null
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 $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()
{
@ -33,7 +28,6 @@ class Avatar extends Managed_DataObject
'height' => array('type' => 'int', 'not null' => true, 'description' => 'image height'),
'mediatype' => array('type' => 'varchar', 'length' => 32, 'not null' => true, 'description' => 'file type'),
'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'),
'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),
),
@ -211,12 +205,7 @@ class Avatar extends Managed_DataObject
function displayUrl()
{
$server = common_config('avatar', 'server');
if ($server && !empty($this->filename)) {
return Avatar::url($this->filename);
} else {
return $this->url;
}
return Avatar::url($this->filename);
}
static function urlByProfile(Profile $target, $width=null, $height=null) {
@ -256,7 +245,6 @@ class Avatar extends Managed_DataObject
$scaled->original = false;
$scaled->width = $width;
$scaled->height = $height;
$scaled->url = Avatar::url($filename);
$scaled->filename = $filename;
$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->filename = $filename;
$avatar->original = true;
$avatar->url = Avatar::url($filename);
$avatar->created = common_sql_now();
// XXX: start a transaction here

View File

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

View File

@ -51,7 +51,6 @@ function updateUserUrls()
$profile = $user->getProfile();
updateProfileUrl($profile);
updateAvatarUrls($profile);
} catch (Exception $e) {
echo "Error updating URLs: " . $e->getMessage();
}
@ -67,36 +66,6 @@ function updateProfileUrl($profile)
$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()
{
printfnq("Updating group URLs...\n");