summaryrefslogtreecommitdiff
path: root/classes
diff options
context:
space:
mode:
Diffstat (limited to 'classes')
-rw-r--r--classes/File.php10
-rw-r--r--classes/Memcached_DataObject.php50
-rw-r--r--classes/Notice.php18
-rw-r--r--classes/Profile.php128
-rw-r--r--classes/Queue_item.php11
-rw-r--r--classes/User.php2
6 files changed, 169 insertions, 50 deletions
diff --git a/classes/File.php b/classes/File.php
index 5dd7cd865..533cc6e71 100644
--- a/classes/File.php
+++ b/classes/File.php
@@ -122,17 +122,17 @@ class File extends Memcached_DataObject
return $x;
}
- function isRespectsQuota($user) {
- if ($_FILES['attach']['size'] > common_config('attachments', 'file_quota')) {
+ function isRespectsQuota($user,$fileSize) {
+ if ($fileSize > common_config('attachments', 'file_quota')) {
return sprintf(_('No file may be larger than %d bytes ' .
'and the file you sent was %d bytes. Try to upload a smaller version.'),
- common_config('attachments', 'file_quota'), $_FILES['attach']['size']);
+ common_config('attachments', 'file_quota'), $fileSize);
}
$query = "select sum(size) as total from file join file_to_post on file_to_post.file_id = file.id join notice on file_to_post.post_id = notice.id where profile_id = {$user->id} and file.url like '%/notice/%/file'";
$this->query($query);
$this->fetch();
- $total = $this->total + $_FILES['attach']['size'];
+ $total = $this->total + $fileSize;
if ($total > common_config('attachments', 'user_quota')) {
return sprintf(_('A file this large would exceed your user quota of %d bytes.'), common_config('attachments', 'user_quota'));
}
@@ -140,7 +140,7 @@ class File extends Memcached_DataObject
$query .= ' month(modified) = month(now()) and year(modified) = year(now())';
$this->query($query);
$this->fetch();
- $total = $this->total + $_FILES['attach']['size'];
+ $total = $this->total + $fileSize;
if ($total > common_config('attachments', 'monthly_quota')) {
return sprintf(_('A file this large would exceed your monthly quota of %d bytes.'), common_config('attachments', 'monthly_quota'));
}
diff --git a/classes/Memcached_DataObject.php b/classes/Memcached_DataObject.php
index 96f8d520b..f7cbb9d5b 100644
--- a/classes/Memcached_DataObject.php
+++ b/classes/Memcached_DataObject.php
@@ -33,41 +33,21 @@ class Memcached_DataObject extends DB_DataObject
$k = $keys[0];
unset($i);
}
- $i = self::getcached($cls, $k, $v);
+ $i = Memcached_DataObject::getcached($cls, $k, $v);
if ($i) {
return $i;
} else {
$i = DB_DataObject::staticGet($cls, $k, $v);
if ($i) {
$i->encache();
- } else {
- self::cachenull($cls, $k, $v);
}
return $i;
}
}
- function cachenull($cls, $k, $v)
- {
- $c = self::memcache();
- if (empty($c)) {
- return;
- }
- $c->set(self::cacheKey($cls, $k, $v), null);
- }
-
- function multicachenull($cls, $kv)
- {
- $c = self::memcache();
- if (empty($c)) {
- return;
- }
- $c->set(self::multicachekey($cls, $kv), null);
- }
-
function &pkeyGet($cls, $kv)
{
- $i = self::multicache($cls, $kv);
+ $i = Memcached_DataObject::multicache($cls, $kv);
if ($i) {
return $i;
} else {
@@ -78,7 +58,6 @@ class Memcached_DataObject extends DB_DataObject
if ($i->find(true)) {
$i->encache();
} else {
- self::multicachenull($cls, $kv);
$i = null;
}
return $i;
@@ -88,9 +67,6 @@ class Memcached_DataObject extends DB_DataObject
function insert()
{
$result = parent::insert();
- if ($result) {
- $this->encache();
- }
return $result;
}
@@ -121,11 +97,11 @@ class Memcached_DataObject extends DB_DataObject
}
static function getcached($cls, $k, $v) {
- $c = self::memcache();
+ $c = Memcached_DataObject::memcache();
if (!$c) {
return false;
} else {
- return $c->get(self::cacheKey($cls, $k, $v));
+ return $c->get(Memcached_DataObject::cacheKey($cls, $k, $v));
}
}
@@ -192,23 +168,17 @@ class Memcached_DataObject extends DB_DataObject
function multicache($cls, $kv)
{
- $c = self::memcache();
+ ksort($kv);
+ $c = Memcached_DataObject::memcache();
if (!$c) {
return false;
} else {
- return $c->get(self::multicachekey($cls, $kv));
+ $pkeys = implode(',', array_keys($kv));
+ $pvals = implode(',', array_values($kv));
+ return $c->get(Memcached_DataObject::cacheKey($cls, $pkeys, $pvals));
}
}
- function multicachekey($cls, $kv)
- {
- ksort($kv);
- $pkeys = implode(',', array_keys($kv));
- $pvals = implode(',', array_values($kv));
-
- return self::cacheKey($cls, $pkeys, $pvals);
- }
-
function getSearchEngine($table)
{
require_once INSTALLDIR.'/lib/search_engines.php';
@@ -241,7 +211,7 @@ class Memcached_DataObject extends DB_DataObject
static function cachedQuery($cls, $qry, $expiry=3600)
{
- $c = self::memcache();
+ $c = Memcached_DataObject::memcache();
if (!$c) {
$inst = new $cls();
$inst->query($qry);
diff --git a/classes/Notice.php b/classes/Notice.php
index 8a018068a..75044cf63 100644
--- a/classes/Notice.php
+++ b/classes/Notice.php
@@ -356,6 +356,8 @@ class Notice extends Memcached_DataObject
$this->blowTagCache($blowLast);
$this->blowGroupCache($blowLast);
$this->blowConversationCache($blowLast);
+ $profile = Profile::staticGet($this->profile_id);
+ $profile->blowNoticeCount();
}
function blowConversationCache($blowLast=false)
@@ -1164,6 +1166,18 @@ class Notice extends Memcached_DataObject
}
$tag->free();
+ # Enclosures
+ $attachments = $this->attachments();
+ if($attachments){
+ foreach($attachments as $attachment){
+ $attributes = array('rel'=>'enclosure','href'=>$attachment->url,'type'=>$attachment->mimetype,'length'=>$attachment->size);
+ if($attachment->title){
+ $attributes['title']=$attachment->title;
+ }
+ $xs->element('link', $attributes, null);
+ }
+ }
+
$xs->elementEnd('entry');
return $xs->getString();
@@ -1210,7 +1224,7 @@ class Notice extends Memcached_DataObject
$window = explode(',', $laststr);
$last_id = $window[0];
$new_ids = call_user_func_array($fn, array_merge($args, array(0, NOTICE_CACHE_WINDOW,
- $last_id, 0, null, $tag)));
+ $last_id, 0, null)));
$new_window = array_merge($new_ids, $window);
@@ -1225,7 +1239,7 @@ class Notice extends Memcached_DataObject
}
$window = call_user_func_array($fn, array_merge($args, array(0, NOTICE_CACHE_WINDOW,
- 0, 0, null, $tag)));
+ 0, 0, null)));
$windowstr = implode(',', $window);
diff --git a/classes/Profile.php b/classes/Profile.php
index a0ed6b3ca..224b61bd2 100644
--- a/classes/Profile.php
+++ b/classes/Profile.php
@@ -337,4 +337,132 @@ class Profile extends Memcached_DataObject
return $profile;
}
+
+ function subscriptionCount()
+ {
+ $c = common_memcache();
+
+ if (!empty($c)) {
+ $cnt = $c->get(common_cache_key('profile:subscription_count:'.$this->id));
+ if (is_integer($cnt)) {
+ return (int) $cnt;
+ }
+ }
+
+ $sub = new Subscription();
+ $sub->subscriber = $this->id;
+
+ $cnt = (int) $sub->count('distinct subscribed');
+
+ $cnt = ($cnt > 0) ? $cnt - 1 : $cnt;
+
+ if (!empty($c)) {
+ $c->set(common_cache_key('profile:subscription_count:'.$this->id), $cnt);
+ }
+
+ common_debug("subscriptionCount == $cnt");
+ return $cnt;
+ }
+
+ function subscriberCount()
+ {
+ $c = common_memcache();
+ if (!empty($c)) {
+ $cnt = $c->get(common_cache_key('profile:subscriber_count:'.$this->id));
+ if (is_integer($cnt)) {
+ return (int) $cnt;
+ }
+ }
+
+ $sub = new Subscription();
+ $sub->subscribed = $this->id;
+
+ $cnt = (int) $sub->count('distinct subscriber');
+
+ $cnt = ($cnt > 0) ? $cnt - 1 : $cnt;
+
+ if (!empty($c)) {
+ $c->set(common_cache_key('profile:subscriber_count:'.$this->id), $cnt);
+ }
+
+ common_debug("subscriberCount == $cnt");
+ return $cnt;
+ }
+
+ function faveCount()
+ {
+ $c = common_memcache();
+ if (!empty($c)) {
+ $cnt = $c->get(common_cache_key('profile:fave_count:'.$this->id));
+ if (is_integer($cnt)) {
+ return (int) $cnt;
+ }
+ }
+
+ $faves = new Fave();
+ $faves->user_id = $this->id;
+ $cnt = (int) $faves->count('distinct notice_id');
+
+ if (!empty($c)) {
+ $c->set(common_cache_key('profile:fave_count:'.$this->id), $cnt);
+ }
+
+ common_debug("faveCount == $cnt");
+ return $cnt;
+ }
+
+ function noticeCount()
+ {
+ $c = common_memcache();
+
+ if (!empty($c)) {
+ $cnt = $c->get(common_cache_key('profile:notice_count:'.$this->id));
+ if (is_integer($cnt)) {
+ return (int) $cnt;
+ }
+ }
+
+ $notices = new Notice();
+ $notices->profile_id = $this->id;
+ $cnt = (int) $notices->count('distinct id');
+
+ if (!empty($c)) {
+ $c->set(common_cache_key('profile:notice_count:'.$this->id), $cnt);
+ }
+
+ common_debug("noticeCount == $cnt");
+ return $cnt;
+ }
+
+ function blowSubscriberCount()
+ {
+ $c = common_memcache();
+ if (!empty($c)) {
+ $c->delete(common_cache_key('profile:subscriber_count:'.$this->id));
+ }
+ }
+
+ function blowSubscriptionCount()
+ {
+ $c = common_memcache();
+ if (!empty($c)) {
+ $c->delete(common_cache_key('profile:subscription_count:'.$this->id));
+ }
+ }
+
+ function blowFaveCount()
+ {
+ $c = common_memcache();
+ if (!empty($c)) {
+ $c->delete(common_cache_key('profile:fave_count:'.$this->id));
+ }
+ }
+
+ function blowNoticeCount()
+ {
+ $c = common_memcache();
+ if (!empty($c)) {
+ $c->delete(common_cache_key('profile:notice_count:'.$this->id));
+ }
+ }
}
diff --git a/classes/Queue_item.php b/classes/Queue_item.php
index 9b909ec22..295c321b5 100644
--- a/classes/Queue_item.php
+++ b/classes/Queue_item.php
@@ -4,7 +4,7 @@
*/
require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
-class Queue_item extends Memcached_DataObject
+class Queue_item extends Memcached_DataObject
{
###START_AUTOCODE
/* the code below is auto generated do not remove the above tag */
@@ -13,7 +13,7 @@ class Queue_item extends Memcached_DataObject
public $notice_id; // int(4) primary_key not_null
public $transport; // varchar(8) primary_key not_null
public $created; // datetime() not_null
- public $claimed; // datetime()
+ public $claimed; // datetime()
/* Static get */
function staticGet($k,$v=null)
@@ -24,7 +24,7 @@ class Queue_item extends Memcached_DataObject
function sequenceKey()
{ return array(false, false); }
-
+
static function top($transport) {
$qi = new Queue_item();
@@ -54,4 +54,9 @@ class Queue_item extends Memcached_DataObject
$qi = null;
return null;
}
+
+ function &pkeyGet($kv)
+ {
+ return Memcached_DataObject::pkeyGet('Queue_item', $kv);
+ }
}
diff --git a/classes/User.php b/classes/User.php
index 04b38a0d2..6c1f149e4 100644
--- a/classes/User.php
+++ b/classes/User.php
@@ -494,6 +494,8 @@ class User extends Memcached_DataObject
$cache->delete(common_cache_key('fave:ids_by_user_own:'.$this->id));
$cache->delete(common_cache_key('fave:ids_by_user_own:'.$this->id.';last'));
}
+ $profile = $this->getProfile();
+ $profile->blowFaveCount();
}
function getSelfTags()