alf (red_alf) wrote in changelog,
alf
red_alf
changelog

[livejournal] r20952: LJSUP-10900: Implement MessagePack proto...

Committer: afedorov
LJSUP-10900: Implement MessagePack protocol driver to access to Relation Service.

U   trunk/cgi-bin/LJ/RelationService.pm
Modified: trunk/cgi-bin/LJ/RelationService.pm
===================================================================
--- trunk/cgi-bin/LJ/RelationService.pm	2012-01-23 08:42:20 UTC (rev 20951)
+++ trunk/cgi-bin/LJ/RelationService.pm	2012-01-23 09:04:55 UTC (rev 20952)
@@ -1,16 +1,28 @@
 package LJ::RelationService;
 use strict;
 
+use LJ::ExtBlock;
+use LJ::JSON;
+
 use LJ::RelationService::RSAPI;
 use LJ::RelationService::MysqlAPI;
 
+my $PARAMS = {};
+
 sub _load_alt_api {
-    my $class = shift;
-    my $user  = shift;
+    my $class  = shift;
+    my $method = shift;
 
     return 0 unless LJ::is_enabled('send_test_load_to_rs2');
 
-    my $rate = $LJ::RELATION_SERVICE_LOAD_RATE; ## 0 .. 100
+    my $ext_block = LJ::ExtBlock->load_by_id('lj11_params');
+    my $values = $ext_block ? LJ::JSON->from_json($ext_block->blocktext) : {};
+    $PARAMS->{rs_ratio_read} = $values->{rs_ratio_read} || 0;
+    $PARAMS->{rs_ratio_update} = $values->{rs_ratio_update} || 0;
+    
+    my $rate = ($method eq 'read')   ? $PARAMS->{rs_ratio_read} :
+               ($method eq 'update') ? $PARAMS->{rs_ratio_update} : 0;
+    
     return 0 unless $rate;
 
     ##
@@ -38,7 +50,7 @@
     my $class = shift;
     my $u     = shift;
 
-    if ($class->_load_alt_api($u)){
+    if ($class->_load_alt_api('read')){
         my $alt = $class->alt_api($u);
         if ($alt){
             $alt->find_relation_destinations($u, @_);
@@ -55,7 +67,7 @@
     my $class = shift;
     my $u     = shift;
 
-    if ($class->_load_alt_api($u)){
+    if ($class->_load_alt_api('read')){
         my $alt = $class->alt_api($u);
         if ($alt){
             $alt->find_relation_sources($u, @_);
@@ -80,7 +92,7 @@
     my $class = shift;
     my $u     = shift;
 
-    if ($class->_load_alt_api($u)){
+    if ($class->_load_alt_api('update')){
         my $alt = $class->alt_api($u);
         if ($alt){
             $alt->create_relation_to($u, @_);
@@ -96,7 +108,7 @@
     my $class = shift;
     my $u     = shift;
 
-    if ($class->_load_alt_api($u)){
+    if ($class->_load_alt_api('update')){
         my $alt = $class->alt_api($u);
         if ($alt){
             $alt->create_relation_to($u, @_);
@@ -106,7 +118,4 @@
     return $interface->remove_relation_to($u, @_);
 }
 
-
-
-
-1
+1;

Tags: afedorov, livejournal, pm, red_alf
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