title: How to better implement Like/Unlike System using mysql
body: <p>I am developing a like/unlike system for my Wordpress Multisite using jquery, php and mysql. Basically, sub-sites have posts and products where user can like and unlike them. My plan is to store the likes in a global table so I can use it also for the main site to display the posts and the number of likes and have a separate page for the Most Liked Posts/products and some sort.</p>
  
  <p>In my mysql table naming <code>global_likes</code> I have these columns.</p>
  
  <p><code>like_id | user_id | blog_id | object_id | object_type | date_added</code></p>
  
  <p>Example Datas would be:</p>
  
  <pre><code>like_id | user_id | blog_id | object_id | object_type | date_added
  
  1       | 24      | 81      | 403       | post        | 2014-01-22 05:55:23
  
  2       | 36      | 29      | 108       | product     | 2013-02-26 12:23:10
  </code></pre>
  
  <p>In my jquery I use this as part:</p>
  
  <pre><code>jQuery.ajax({
      url: '/wp-content/plugins/plugname/like.php',
      type: 'POST',
      data: {
          object_id: object_id,
          user_id: user_id,
          type: 'like',
          blog_id: blog_id,
          object_type: object_type,
          count: default_count
      },
      dataType: 'json',
      success: function(data) {
          var new_count = parseInt(default_count) + 1;
          jQuery('#like_click_' + object_id).attr('data-like-count', new_count);              
          jQuery('#like_click_' + object_id).attr('id', '#unlike_click_' + object_id);
          isProcessing = false;
      }
  });
  </code></pre>
  
  <p>In my server side PHP I use this as part which inserts the datas after some sort of validation:</p>
  
  <pre><code>$wpdb-&gt;insert( 
  $global_likes, 
  array( 
      'user_id' =&gt; $user_id, 
      'blog_id' =&gt; $blog_id, 
      'object_id' =&gt; $object_id, 
      'object_type' =&gt; $object_type,
      'date_added' =&gt; $date_added
  )
  );
  </code></pre>
  
  <p>Thats it. Now, the problem is it is expected to have many rows as likes get inserted by different users on different posts/products from different blogs. Its like thousands or millions just like that.</p>
  
  <p>Is that a overkill?? or may cause heavy load as I use currently 512mb application RAM. I'm greatly concerned with the performance and CPU usage. Considering that the likes are obtained on each posts/products from different blogs and at the same time, it is displayed also on the main site which displays all the posts from across the blogs along with the number of likes. Also, users can also like/unlike a post from the main site.</p>
  
  <p>Example is:
  When displaying a post or product either on a specific blog or in main site,</p>
  
  <ul>
  <li>The number of likes is being queried and displayed.</li>
  <li>Check if user has or has not liked the post by checking the <code>user_id</code>
  on the global table.</li>
  <li>User can unlike/like the post or product.</li>
  </ul>
  
  <p>On main site also in User profile page.</p>
  
  <ul>
  <li>The global likes table is being queried to check for the user's liked items and displayed.</li>
  <li>The number of liked items from across the network.</li>
  </ul>
  
  <p>Am I using the correct and better way to implement this OR is there a more better way. I only know php, jquery and mysql. If you're thinking of like <code>nosql</code> or same like that, It might not help me since I'm using wordpress and I don't know how to us it at all.</p>