Андрей (andy) wrote in changelog,
Андрей
andy
changelog

[livejournal] r16121: LJSV-878:

Committer: ailyin
LJSV-878:

- do not use constants that no longer exist
- create an API to get subscriptions count (the count the quota applies to, that is)

U   trunk/cgi-bin/LJ/Subscription/GroupSet.pm
U   trunk/cgi-bin/LJ/Subscription.pm
U   trunk/cgi-bin/LJ/User.pm
Modified: trunk/cgi-bin/LJ/Subscription/GroupSet.pm
===================================================================
--- trunk/cgi-bin/LJ/Subscription/GroupSet.pm	2010-01-25 05:52:36 UTC (rev 16120)
+++ trunk/cgi-bin/LJ/Subscription/GroupSet.pm	2010-01-25 06:43:30 UTC (rev 16121)
@@ -2,6 +2,8 @@
 
 use strict;
 
+use LJ::MemCache;
+
 use LJ::Subscription::Group;
 use LJ::Subscription::QuotaError;
 
@@ -384,6 +386,8 @@
     my $sets = join(' AND ', @sets);
 
     $self->_dbh->do("DELETE FROM subs WHERE $sets", undef, @binds);
+
+    LJ::MemCache::delete('subscriptions_count:'.$self->user->id);
 }
 
 sub _db_collect_sets_binds {
@@ -419,6 +423,8 @@
     my $subid = LJ::alloc_user_counter($self->user, 'E');
 
     $self->_dbh->do("INSERT INTO subs SET $sets, subid=?", undef, @binds, $subid);
+
+    LJ::MemCache::delete('subscriptions_count:'.$self->user->id);
 }
 
 sub _db_update_sub {
@@ -444,6 +450,7 @@
     my $sets = join(' AND ', @sets);
 
     $self->_dbh->do("DELETE FROM subs WHERE $sets", undef, @binds);
+    LJ::MemCache::delete('subscriptions_count:'.$self->user->id);
 }
 
 1;

Modified: trunk/cgi-bin/LJ/Subscription.pm
===================================================================
--- trunk/cgi-bin/LJ/Subscription.pm	2010-01-25 05:52:36 UTC (rev 16120)
+++ trunk/cgi-bin/LJ/Subscription.pm	2010-01-25 06:43:30 UTC (rev 16121)
@@ -224,7 +224,7 @@
     foreach my $subscr (@subs) {
         # Don't deactivate if the Inbox is always subscribed to
         my $always_checked = $subscr->event_class->always_checked ? 1 : 0;
-        if ($subscr->is_tracking_category && ! $force) {
+        unless ($force) {
             # delete non-inbox methods if we're deactivating
             if ($subscr->method eq 'LJ::NotificationMethod::Inbox' && !$always_checked) {
                 $subscr->_deactivate;
@@ -250,6 +250,8 @@
     # delete from cache in user
     undef $u->{_subscriptions};
 
+    LJ::MemCache::delete('subscriptions_count:'.$u->id);
+
     return 1;
 }
 
@@ -261,6 +263,8 @@
     $u->do("DELETE FROM subs WHERE userid = ?", undef, $u->id);
     undef $u->{_subscriptions};
 
+    LJ::MemCache::delete('subscriptions_count:'.$u->id);
+
     return 1;
 }
 
@@ -382,6 +386,8 @@
     $self->subscriptions_of_user($u) unless $u->{_subscriptions};
     push @{$u->{_subscriptions}}, $self;
 
+    LJ::MemCache::delete('subscriptions_count:'.$u->id);
+
     return $self;
 }
 
@@ -408,11 +414,6 @@
     return $evtclass->subscription_as_html($self);
 }
 
-sub set_tracking {
-    my $self = shift;
-    $self->set_flag(TRACKING);
-}
-
 sub activate {
     my $self = shift;
     $self->clear_flag(INACTIVE);
@@ -486,11 +487,6 @@
     return ! ($self->flags & INACTIVE);
 }
 
-sub is_tracking_category {
-    my $self = shift;
-    return $self->flags & TRACKING;
-}
-
 sub expiretime {
     my $self = shift;
     return $self->{expiretime};
@@ -628,6 +624,11 @@
     return LJ::Subscription::Group->group_from_sub($self);
 }
 
+sub event {
+    my ($self) = @_;
+    return $self->group->event;
+}
+
 package LJ::Error::Subscription::TooMany;
 sub fields { qw(subscr u); }
 

Modified: trunk/cgi-bin/LJ/User.pm
===================================================================
--- trunk/cgi-bin/LJ/User.pm	2010-01-25 05:52:36 UTC (rev 16120)
+++ trunk/cgi-bin/LJ/User.pm	2010-01-25 06:43:30 UTC (rev 16121)
@@ -5500,6 +5500,26 @@
     LJ::set_userprop($u, 'custom_usericon', $url);
 }
 
+sub _subscriptions_count {
+    my ($u) = @_;
+
+    my $set = LJ::Subscription::GroupSet->fetch_for_user($u);
+    my @groups = grep { $_->is_tracking } $set->groups;
+
+    return scalar(@groups);
+}
+
+sub subscriptions_count {
+    my ($u) = @_;
+
+    my $cached = LJ::MemCache::get('subscriptions_count:'.$u->id);
+    return $cached if defined $cached;
+
+    my $count = $u->_subscriptions_count;
+    LJ::MemCache::set('subscriptions_count:'.$u->id, $count);
+    return $count;
+}
+
 package LJ;
 
 use Carp;

Tags: andy, livejournal, pm
Subscribe

  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments