wisest owl (wisest_owl) wrote in changelog,
wisest owl
wisest_owl
changelog

[livejournal] r19067: LJSUP-8840. Remove requests to FB for ev...

Committer: gprochaev
LJSUP-8840. Remove requests to FB for every page request

U   trunk/bin/upgrading/update-db-general.pl
U   trunk/bin/worker/category-recent-posts
U   trunk/cgi-bin/LJ/Browse/Parser.pm
U   trunk/cgi-bin/LJ/Widget/Browse.pm
Modified: trunk/bin/upgrading/update-db-general.pl
===================================================================
--- trunk/bin/upgrading/update-db-general.pl	2011-05-17 07:26:59 UTC (rev 19066)
+++ trunk/bin/upgrading/update-db-general.pl	2011-05-17 11:08:07 UTC (rev 19067)
@@ -3379,6 +3379,8 @@
   timecreate datetime NOT NULL,
   journalid int(10) unsigned NOT NULL,
   is_deleted tinyint(1) NOT NULL default '0',
+  pic_orig_url VARCHAR(255) NOT NULL DEFAULT '',
+  pic_fb_url VARCHAR(255) NOT NULL DEFAULT '',
   PRIMARY KEY  (`journalid`,`jitemid`),
   KEY `timecreate` (`timecreate`),
   KEY `journalid` (`journalid`)
@@ -4341,6 +4343,13 @@
         do_alter("category", "ALTER TABLE category MODIFY parentcatid INT UNSIGNED NOT NULL");
     }
 
+    if (column_type("category_recent_posts", "pic_orig_url")) {
+        do_alter("category_recent_posts",
+            "ALTER TABLE category_recent_posts
+                ADD pic_orig_url VARCHAR(255) NOT NULL DEFAULT '',
+                ADD pic_fb_url VARCHAR(255) NOT NULL DEFAULT ''
+        ");
+    }
 });
 
 register_tablecreate("eventrates", <<'EOC'); # clustered

Modified: trunk/bin/worker/category-recent-posts
===================================================================
--- trunk/bin/worker/category-recent-posts	2011-05-17 07:26:59 UTC (rev 19066)
+++ trunk/bin/worker/category-recent-posts	2011-05-17 11:08:07 UTC (rev 19067)
@@ -13,6 +13,7 @@
 use base 'LJ::NewWorker::Manual';
 
 use LJ::Browse;
+use LJ::Browse::Parser;
 
 # how long to wait if we didn't process any at all
 my $sleep_when_idle;
@@ -70,8 +71,18 @@
             my $sth = $dbh->prepare ("INSERT INTO category_recent_posts (jitemid, timecreate, journalid) VALUES (?, ?, ?)");
             $sth->execute($entry->{itemid}, $entry->{logtime}, $journalid);
 
+            my $e_obj = LJ::Entry->new ($u->{userid}, jitemid => $entry->{itemid});
+            my $event = $e_obj->event_raw;
+
+            my $parsed = LJ::Browse::Parser->do_parse (
+                text        => $event,
+                remove_tags => [ 'b', 'p', 'div', 'span', 'strong', 'font' ],
+                max_len     => 400,
+                crop_image  => 1,
+                entry       => $e_obj,
+            );
+
             ## Add tags for every entry
-            my $e_obj = LJ::Entry->new ($u->{userid}, jitemid => $entry->{itemid});
             my $poster = $e_obj->poster;
             next if $poster->is_suspended;
             next if $e_obj->is_suspended;
@@ -87,6 +98,25 @@
 
     }
 
+=head
+    ## Remove old posts
+    my $verticals = $dbh->selectall_arrayref ("SELECT vert_id, not_deleted, remove_after FROM vertical2", { Slice => {} });
+    foreach my $vert (@$verticals) {
+        next unless $vert->{'remove_after'} && $vert->{'not_deleted'};
+        my $cats = $dbh->selectcol_arrayref ("SELECT catid FROM category WHERE vert_id = ?", { Slice => {} }, $vert->{'vert_id'});
+        foreach my $catid (@$cats) {
+            my $comms = $dbh->selectcol_arrayref ("SELECT DISTINCT journalid FROM categoryjournals WHERE catid = ?", undef, $catid);
+            foreach my $journalid (@$comms) {
+                my $jitems = $dbh->selectcol_arrayref ("SELECT jitemid FROM category_recent_posts WHERE journalid = ? AND unix_timestamp(timecreate) < unix_timestamp() - ".$vert->{'remove_after'}." * 3600 ORDER BY timecreate DESC", undef, $journalid);
+                next unless @$jitems;
+                my @to_delete = splice @$jitems, 0, scalar @$jitems - $vert->{'not_deleted'};
+                next unless @to_delete;
+                my $res = $dbh->do ("DELETE FROM category_recent_posts WHERE jitemid in (".join (",", @to_delete).") AND journalid = ?", undef, $journalid);
+            }
+        }
+    }
+=cut
+
     return 0;
 }
 

Modified: trunk/cgi-bin/LJ/Browse/Parser.pm
===================================================================
--- trunk/cgi-bin/LJ/Browse/Parser.pm	2011-05-17 07:26:59 UTC (rev 19066)
+++ trunk/cgi-bin/LJ/Browse/Parser.pm	2011-05-17 11:08:07 UTC (rev 19067)
@@ -19,6 +19,7 @@
 
     my $text = $args{'text'};
     my $char_max = $args{'max_len'};
+    my $entry = $args{'entry'};
 
     my $p = HTML::TokeParser->new(\$text);
 
@@ -50,17 +51,48 @@
                 ## Img URL must be valid
                 next if $@;
 
-                my $r = $images_crop_cnt ? LJ::crop_picture_from_web(
-                    source      => $attr->{'src'},
-                    size        => '200x200',
-                    cancel_size => '200x0',
-                    username    => $LJ::PHOTOS_FEAT_POSTS_FB_USERNAME,
-                    password    => $LJ::PHOTOS_FEAT_POSTS_FB_PASSWORD,
-                    galleries   => [ $LJ::PHOTOS_FEAT_POSTS_FB_GALLERY ],
-                ) : {};
+                ## Hashref with resized image
+                my $r = undef;
+
+                ## Are we need to update db?
+                my $is_new_img = 0;
+
+                my $jitemid = $entry->jitemid;
+                my $journalid = $entry->journalid;
+                my $dbw = LJ::get_db_writer();
+                if ($images_crop_cnt) {
+                    my $post = $dbw->selectrow_arrayref ("
+                        SELECT pic_orig_url, pic_fb_url 
+                            FROM category_recent_posts 
+                            WHERE jitemid = ? AND journalid = ?", undef,
+                        $jitemid, $journalid
+                    );
+                    if ($post->[0] eq $attr->{'src'}) {
+                        $r = {
+                            status  => 'big',
+                            url     => $post->[1],
+                        };
+                    } else {
+                        $r = LJ::crop_picture_from_web(
+                            source      => $attr->{'src'},
+                            size        => '200x200',
+                            cancel_size => '200x0',
+                            username    => $LJ::PHOTOS_FEAT_POSTS_FB_USERNAME,
+                            password    => $LJ::PHOTOS_FEAT_POSTS_FB_PASSWORD,
+                            galleries   => [ $LJ::PHOTOS_FEAT_POSTS_FB_GALLERY ],
+                        );
+                        $is_new_img = 1;
+                    }
+                }
                 if ($images_crop_cnt && $r && ($r->{'status'} ne 'small') && $r->{'url'}) {
                     $images_crop_cnt--;
                     push @images, $r->{url};
+                    $dbw->do ("
+                        UPDATE category_recent_posts
+                            SET pic_orig_url = ?, pic_fb_url = ? 
+                            WHERE jitemid = ? AND journalid = ?", undef,
+                        $attr->{'src'}, $r->{'url'}, $jitemid, $journalid
+                    ) if $is_new_img;
                     next;
                 } elsif ($r && $r->{'status'} ne 'small') {
                     next;

Modified: trunk/cgi-bin/LJ/Widget/Browse.pm
===================================================================
--- trunk/cgi-bin/LJ/Widget/Browse.pm	2011-05-17 07:26:59 UTC (rev 19066)
+++ trunk/cgi-bin/LJ/Widget/Browse.pm	2011-05-17 11:08:07 UTC (rev 19067)
@@ -280,6 +280,7 @@
                 remove_tags => [ 'b', 'p', 'div', 'span', 'strong', 'font' ],
                 max_len     => 400,
                 crop_image  => 1,
+                entry       => $entry,
             );
             $event = $parsed->{'text'};
             my $images = $parsed->{'images'};

Tags: livejournal, pl, pm, wisest-owl
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