mirror of
https://github.com/owncloudarchive/contacts.git
synced 2024-12-01 13:24:10 +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
|
||||
*/
|
||||
Contact.prototype.setThumbnail = function(refresh) {
|
||||
if(this.getPreferredValue('PHOTO', null) === null) {
|
||||
if(!this.data.thumbnail) {
|
||||
return;
|
||||
}
|
||||
var $elem = this.getListItemElement().find('td.name');
|
||||
if(!$elem.hasClass('thumbnail')) {
|
||||
if(!$elem.hasClass('thumbnail') && !refresh) {
|
||||
return;
|
||||
}
|
||||
$elem.removeClass('thumbnail');
|
||||
var refreshstr = refresh ? '&refresh='+Math.random() : '';
|
||||
$elem.css('background-image', 'url(' + OC.filePath('', '', 'remote.php')
|
||||
+'/contactthumbnail?backend='
|
||||
+this.metadata.backend+'&parent='
|
||||
+this.metadata.parent+'&id='
|
||||
+this.id+refreshstr + ')'
|
||||
);
|
||||
$elem.css('background-image', 'url(data:image/png;base64,' + this.data.thumbnail + ')');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -611,8 +611,8 @@ class Contact extends VObject\VCard implements IPIMObject {
|
||||
\OCP\Util::ERROR);
|
||||
return false;
|
||||
}
|
||||
// Cache for around a month
|
||||
\OC_Cache::set(self::THUMBNAIL_PREFIX . $key, $image->data(), 3000000);
|
||||
// Cache as base64 for around a month
|
||||
\OC_Cache::set(self::THUMBNAIL_PREFIX . $key, strval($image), 3000); //3000000);
|
||||
\OCP\Util::writeLog('contacts', 'Caching ' . $key, \OCP\Util::DEBUG);
|
||||
return \OC_Cache::get(self::THUMBNAIL_PREFIX . $key);
|
||||
}
|
||||
|
@ -89,6 +89,10 @@ class JSONSerializer {
|
||||
|
||||
$details = array();
|
||||
|
||||
if(isset($contact->PHOTO) || isset($contact->LOGO)) {
|
||||
$details['thumbnail'] = $contact->cacheThumbnail();
|
||||
}
|
||||
|
||||
foreach($contact->children as $property) {
|
||||
$pname = $property->name;
|
||||
$temp = self::serializeProperty($property);
|
||||
|
Loading…
Reference in New Issue
Block a user