Committer: vad
LJLMI-7: add to MSN init call mutual friends with WL ID.U branches/msn/bin/upgrading/update-db-general.pl U branches/msn/cgi-bin/LJ/Comet/History.pm U branches/msn/cgi-bin/ljprotocol.pl
Modified: branches/msn/bin/upgrading/update-db-general.pl =================================================================== --- branches/msn/bin/upgrading/update-db-general.pl 2009-06-04 07:20:19 UTC (rev 15239) +++ branches/msn/bin/upgrading/update-db-general.pl 2009-06-04 08:46:12 UTC (rev 15240) @@ -3989,6 +3989,12 @@ "MODIFY jtalkid INT UNSIGNED NOT NULL"); } + unless (column_type("comet_history", "status")) { + do_alter("comet_history", + "ALTER TABLE comet_history " . + "ADD status char(1) default 'N' after message"); + } + }); Modified: branches/msn/cgi-bin/LJ/Comet/History.pm =================================================================== --- branches/msn/cgi-bin/LJ/Comet/History.pm 2009-06-04 07:20:19 UTC (rev 15239) +++ branches/msn/cgi-bin/LJ/Comet/History.pm 2009-06-04 08:46:12 UTC (rev 15240) @@ -7,7 +7,7 @@ uid integer unsigned not null, type varchar(31), message text, - + status char(1), -- (N)ew, (R)eaded added datetime, INDEX(uid) @@ -37,7 +37,7 @@ ", undef, $u->userid, $type, $msg ) or die "Can't add message to db: " . $dbcm->errstr; - LJ::MemCache::delete("comet:history:" . $u->userid); + LJ::MemCache::delete("comet:history:" . $u->userid . ":$type"); my ($rec_id) = $dbcm->selectrow_array("SELECT LAST_INSERT_ID()"); return @@ -50,29 +50,35 @@ } sub log { - my $class = shift; - my $u = shift; - my $from = int (shift); + my $class = shift; + my $u = shift; + my $type = shift; + my $status = shift || 'N'; + die "Unknown message type" + unless grep {$_ eq $type} qw/alert message post comment/; + + die "Unknown status" + unless $status =~ m/^N|R\z/; + # - my $ckey = "comet:history:" . $u->userid; + my $ckey = "comet:history:" . $u->userid . ":$type"; my $cached = LJ::MemCache::get($ckey); -warn "*********** BEFORE CACHE"; - return $cached if $cached and $cached->{messages}->[0]->{rec_id} eq $from; -warn "*********** AFTER CACHE"; + return $cached if $cached; my @messages = (); my $dbcm = LJ::get_cluster_master($u); my $sth = $dbcm->prepare(" SELECT * FROM comet_history - WHERE - rec_id > ? - AND uid = ? + WHERE + uid = ? + AND type = ? + AND status = ? LIMIT 51 ") or die $dbcm->errstr; - $sth->execute($from, $u->userid) - or die "Can't get comet history from DB: user_id=" . $u->userid . " from=$from Error:" . $dbcm->errstr; + $sth->execute($u->userid, $type, $status) + or die "Can't get comet history from DB: user_id=" . $u->userid . " Error:" . $dbcm->errstr; while (my $h = $sth->fetchrow_hashref){ push @messages => $h; } @@ -83,7 +89,7 @@ messages => [splice @messages, 0 => 50], have_more => $have_more, }; - LJ::MemCache::set($ckey, $res); + LJ::MemCache::set($ckey, $res, $LJ::COMET_HISTORY_LIFETIME); return $res; } @@ -95,5 +101,54 @@ return JSON::objToJson($res); } + +sub mark_as_readed { + my $class = shift; + my $u = shift; + my $to = shift; + my $type = shift; + + die "Unknown message type" + unless grep {$_ eq $type} qw/alert message post comment/; + + # 1. update db + my $dbcm = LJ::get_cluster_master($u); + $dbcm->do(" + UPDATE comet_history + SET status='R' + WHERE + rec_id <= ? + AND uid = ? + AND type = ? + ", undef, + $u->userid, $to, $type + ) or die "Can't mark comet_history records as readed: " . $dbcm->errstr; + + + # 2. invalidate cached data + my $ckey = "comet:history:" . $u->userid . ":$type"; + LJ::MemCache::delete($ckey); + + return 1; +} + +sub remove_outdated { + my $class = shift; + + foreach my $cid (@LJ::CLUSTERS){ + my $dbcw = LJ::get_cluster_master($cid); + die "Unable to get cluster writer for cluster $cid" unless $dbcw; + + $dbcw->do(" + DELETE FROM comet_history + WHERE added < FROM_UNIXTIME(?) + ", undef, + (time - $LJ::COMET_HISTORY_LIFETIME) + ) or die "Could not remove outdated records from 'comet_history': " . $dbcw->errstr; +warn "after delete... cluster: $cid"; + } + return 1; +} + 1; Modified: branches/msn/cgi-bin/ljprotocol.pl =================================================================== --- branches/msn/cgi-bin/ljprotocol.pl 2009-06-04 07:20:19 UTC (rev 15239) +++ branches/msn/cgi-bin/ljprotocol.pl 2009-06-04 08:46:12 UTC (rev 15240) @@ -2304,6 +2304,8 @@ ## first, figure out who the current friends are to save us work later my %curfriend; my $friend_count = 0; + my $friends_changed = 0; + # TAG:FR:protocol:editfriends1 $sth = $dbh->prepare("SELECT u.user FROM useridmap u, friends f ". "WHERE u.userid=f.friendid AND f.userid=$userid"); @@ -2325,6 +2327,7 @@ # TAG:FR:protocol:editfriends2_del LJ::remove_friend($userid, $friendid); $friend_count--; + $friends_changed = 1; } my $error_flag = 0; @@ -2437,7 +2440,7 @@ $sclient->insert_jobs(@jobs) if @jobs; } - + $friends_changed = 1; LJ::run_hooks('befriended', LJ::load_userid($userid), LJ::load_userid($friendid)); } } @@ -2449,6 +2452,8 @@ LJ::memcache_kill($userid, "friends2"); LJ::mark_dirty($userid, "friends"); + LJ::run_hooks('friends_changed', LJ::load_userid($userid)) if $friends_changed; + return $res; }