Первый фоллен на хелле (wildkin) wrote in changelog,
Первый фоллен на хелле
wildkin
changelog

[livejournal] r19154: LJSUP-8908: Internal Server Error when n...

Committer: dnikolaev
LJSUP-8908: Internal Server Error when non-logged user open friends page

U   trunk/cgi-bin/LJ/FriendsTags.pm
U   trunk/cgi-bin/LJ/S2/FriendsPage.pm
U   trunk/cgi-bin/ljviews.pl
U   trunk/htdocs/friends/add.bml
Modified: trunk/cgi-bin/LJ/FriendsTags.pm
===================================================================
--- trunk/cgi-bin/LJ/FriendsTags.pm	2011-05-27 05:18:55 UTC (rev 19153)
+++ trunk/cgi-bin/LJ/FriendsTags.pm	2011-05-27 07:20:55 UTC (rev 19154)
@@ -1,5 +1,8 @@
 package LJ::FriendsTags;
 
+use strict;
+use Encode;
+
 use constant ALLOW => 'A';
 use constant DENY  => 'D';
 use constant MAX_FRIENDSTAGS_SIZE => 65535;
@@ -17,6 +20,7 @@
 sub load {
     my ($class, $remote) = @_;
 
+    return undef unless $remote;
     my $prop = $remote->prop('friends_tags');
     $prop = LJ::text_uncompress($prop);
 
@@ -99,6 +103,7 @@
     $tags_str = '' unless defined $tags_str;
     $tags_str =~ s/^\s+//s;
     $tags_str =~ s/\s+$//s;
+    $tags_str = $self->normalize_tag($tags_str);
 
     if (length($tags_str) > 0) {
         my %tags = map { lc($_) => 1 } split /\s*,\s*/, $tags_str;
@@ -114,6 +119,11 @@
     $self->{_data} = $data;
 }
 
+sub normalize_tag {
+    my ($class, $tag) = @_;
+    return Encode::encode('utf-8', lc(Encode::decode('utf-8', $tag)));
+};
+
 sub filter_func {
     my ($self, $friendid) = @_;
 
@@ -125,7 +135,7 @@
         return sub {
             return 1 unless @_;
             foreach (@_) {
-                return 0 if exists $tags{$_};
+                return 0 if exists $tags{$self->normalize_tag($_)};
             }
             return 1;
         };
@@ -133,7 +143,7 @@
         return sub {
             return 0 unless @_;
             foreach (@_) {
-                return 1 if exists $tags{$_};
+                return 1 if exists $tags{$self->normalize_tag($_)};
             }
             return 0;
         };

Modified: trunk/cgi-bin/LJ/S2/FriendsPage.pm
===================================================================
--- trunk/cgi-bin/LJ/S2/FriendsPage.pm	2011-05-27 05:18:55 UTC (rev 19153)
+++ trunk/cgi-bin/LJ/S2/FriendsPage.pm	2011-05-27 07:20:55 UTC (rev 19154)
@@ -147,6 +147,11 @@
     # use Time::HiRes qw//;
     # my $t0 = [Time::HiRes::gettimeofday];
 
+    my $friends_tags = undef;
+    if ($remote && !$get->{notags}) {
+        $friends_tags = LJ::FriendsTags->load($remote);
+    }
+
     ## load the itemids
     my %friends;
     my %friends_row;
@@ -166,7 +171,7 @@
         'friendsoffriends'  => $opts->{'view'} eq "friendsfriends",
         'dateformat'        => 'S2',
         'events_date'       => $events_date,
-        $get->{notags} ? () : 'filter_by_tags' => LJ::FriendsTags->load($remote),
+        'filter_by_tags'    => $friends_tags,
     });
 
     # warn "[FriendsPage=$user] Items loaded. elapsed=" . Time::HiRes::tv_interval( $t0, [Time::HiRes::gettimeofday]) . " sec";

Modified: trunk/cgi-bin/ljviews.pl
===================================================================
--- trunk/cgi-bin/ljviews.pl	2011-05-27 05:18:55 UTC (rev 19153)
+++ trunk/cgi-bin/ljviews.pl	2011-05-27 07:20:55 UTC (rev 19154)
@@ -1711,6 +1711,11 @@
         }
     }
 
+    my $friends_tags = undef;
+    if ($remote && !$get->{notags}) {
+        $friends_tags = LJ::FriendsTags->load($remote);
+    }
+
     ## load the itemids
     my %friends;
     my %friends_row;
@@ -1729,7 +1734,7 @@
         'showtypes' => $get->{'show'},
         'friendsoffriends' => $opts->{'view'} eq "friendsfriends",
         'events_date' => $events_date,
-        $get->{notags} ? () : 'filter_by_tags' => LJ::FriendsTags->load($remote),
+        'filter_by_tags' => $friends_tags,
     });
 
     while ($_ = each %friends) {

Modified: trunk/htdocs/friends/add.bml
===================================================================
--- trunk/htdocs/friends/add.bml	2011-05-27 05:18:55 UTC (rev 19153)
+++ trunk/htdocs/friends/add.bml	2011-05-27 07:20:55 UTC (rev 19154)
@@ -258,28 +258,24 @@
  }
 
  unless ($u->is_identity()) {
-     my $to_lower_case = sub {
-         my $s = shift;
-         return Encode::encode('utf-8', lc(Encode::decode('utf-8', $s)));
-     };
 
-     my $user_tags_map = LJ::Tags::get_usertags($u, { remote => $remote }) || {};
-     $user_tags_map = {
-         map {
-             $to_lower_case->($_->{name}) => (
-                 $_->{uses} < 2 ?
-                     '' :
-                     ($_->{uses} > 999 ? '(999+)' : "($_->{uses})")
-             )
+     my $user_tags_map = {};
+     {
+         my $tags = LJ::Tags::get_usertags($u, { remote => $remote }) || {};
+         foreach (values %$tags) { 
+             next unless $_->{display};
+             $user_tags_map->{ LJ::FriendsTags->normalize_tag($_->{name}) } += $_->{uses};
          }
-         grep { $_->{display} }
-         values %$user_tags_map
-     };
+         foreach (keys %$user_tags_map) {
+             my $uses = $user_tags_map->{$_};
+             $user_tags_map->{$_} = ($uses < 2 ? '' : ($uses > 999 ? '(999+)' : "($uses)"));
+         }
+     }
 
      my $friends_tags = LJ::FriendsTags->load($remote);
      my ($friend_tags_mode, $friend_tags_list) = $friends_tags->get_tags($u->{userid});
      my $friend_tags_map = {};
-     $friend_tags_list = [ map { $to_lower_case->($_) } @$friend_tags_list ];
+     $friend_tags_list = [ map { LJ::FriendsTags->normalize_tag($_) } @$friend_tags_list ];
 
      $body .= '<div class="b-addfriend-option b-addfriend-tags">';
      $body .= '<h3 class="b-addfriend-subhead">' . $ML{'.tags.read'} . '</h3>';
@@ -301,7 +297,7 @@
      {
          my $not_last = scalar(@$friend_tags_list);
          foreach (@$friend_tags_list) {
-             $body .= '<li><span><a target="_blank" href="#">' . LJ::ehtml($_) . '</a> ' . (exists $user_tags_map->{$_} ? $user_tags_map->{$_} : '(-)') . '<i title="Remove tag from list" class="i-pending-close"></i></span>' . (--$not_last ? '<b>,</b>' : '<b class="i-pending-users-comma">,</b>') . '</li>';
+             $body .= '<li><span><a target="_blank" href="#">' . LJ::ehtml($_) . '</a> ' . (exists $user_tags_map->{$_} ? $user_tags_map->{$_} : '(-)') . '<i title="Remove tag from list" class="i-pending-close"></i></span>' . (--$not_last ? '<b>,</b>' : '') . '</li>';
              $friend_tags_map->{$_} = 1;
          }
      }
@@ -318,7 +314,7 @@
          my @tags = sort grep { !$friend_tags_map->{$_} } keys %$user_tags_map;
          my $not_last = scalar(@tags);
          foreach my $tag (@tags) {
-             $body .= '<li><span><a target="_blank" href="#">' . LJ::ehtml($tag) . '</a> ' . (exists $user_tags_map->{$tag} ? $user_tags_map->{$tag} : '(-)') . '<i title="Remove tag from list" class="i-pending-close"></i></span>' . (--$not_last ? '<b>,</b>' : '<b class="i-pending-users-comma">,</b>') . '</li>';
+             $body .= '<li><span><a target="_blank" href="#">' . LJ::ehtml($tag) . '</a> ' . (exists $user_tags_map->{$tag} ? $user_tags_map->{$tag} : '(-)') . '<i title="Remove tag from list" class="i-pending-close"></i></span>' . (--$not_last ? '<b>,</b>' : '') . '</li>';
          }
      }
 

Tags: bml, livejournal, pl, pm, wildkin
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