mirror of
https://github.com/owncloudarchive/contacts.git
synced 2024-12-03 15:24:09 +01:00
Contacts: Cache thumbnails as base64 an load together with contacts.
Removes the massive amount of requests on first load.
This commit is contained in:
parent
ed349ccab3
commit
9d313b1a1e
@ -1367,21 +1367,15 @@ OC.Contacts = OC.Contacts || {};
|
|||||||
* Set a thumbnail for the contact if a PHOTO property exists
|
* Set a thumbnail for the contact if a PHOTO property exists
|
||||||
*/
|
*/
|
||||||
Contact.prototype.setThumbnail = function(refresh) {
|
Contact.prototype.setThumbnail = function(refresh) {
|
||||||
if(this.getPreferredValue('PHOTO', null) === null) {
|
if(!this.data.thumbnail) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var $elem = this.getListItemElement().find('td.name');
|
var $elem = this.getListItemElement().find('td.name');
|
||||||
if(!$elem.hasClass('thumbnail')) {
|
if(!$elem.hasClass('thumbnail') && !refresh) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$elem.removeClass('thumbnail');
|
$elem.removeClass('thumbnail');
|
||||||
var refreshstr = refresh ? '&refresh='+Math.random() : '';
|
$elem.css('background-image', 'url(data:image/png;base64,' + this.data.thumbnail + ')');
|
||||||
$elem.css('background-image', 'url(' + OC.filePath('', '', 'remote.php')
|
|
||||||
+'/contactthumbnail?backend='
|
|
||||||
+this.metadata.backend+'&parent='
|
|
||||||
+this.metadata.parent+'&id='
|
|
||||||
+this.id+refreshstr + ')'
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -611,8 +611,8 @@ class Contact extends VObject\VCard implements IPIMObject {
|
|||||||
\OCP\Util::ERROR);
|
\OCP\Util::ERROR);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// Cache for around a month
|
// Cache as base64 for around a month
|
||||||
\OC_Cache::set(self::THUMBNAIL_PREFIX . $key, $image->data(), 3000000);
|
\OC_Cache::set(self::THUMBNAIL_PREFIX . $key, strval($image), 3000); //3000000);
|
||||||
\OCP\Util::writeLog('contacts', 'Caching ' . $key, \OCP\Util::DEBUG);
|
\OCP\Util::writeLog('contacts', 'Caching ' . $key, \OCP\Util::DEBUG);
|
||||||
return \OC_Cache::get(self::THUMBNAIL_PREFIX . $key);
|
return \OC_Cache::get(self::THUMBNAIL_PREFIX . $key);
|
||||||
}
|
}
|
||||||
|
@ -89,6 +89,10 @@ class JSONSerializer {
|
|||||||
|
|
||||||
$details = array();
|
$details = array();
|
||||||
|
|
||||||
|
if(isset($contact->PHOTO) || isset($contact->LOGO)) {
|
||||||
|
$details['thumbnail'] = $contact->cacheThumbnail();
|
||||||
|
}
|
||||||
|
|
||||||
foreach($contact->children as $property) {
|
foreach($contact->children as $property) {
|
||||||
$pname = $property->name;
|
$pname = $property->name;
|
||||||
$temp = self::serializeProperty($property);
|
$temp = self::serializeProperty($property);
|
||||||
|
Loading…
Reference in New Issue
Block a user