_binary From bc3f3004115d21cc975f31465f155392909454cc Mon Sep 17 00:00:00 2001
From: Akshat Kukreti <akshatkukreti@gmail.com>
Date: Thu, 25 Oct 2012 18:31:28 -0700
Subject: [PATCH] cache control modified

---
 controllers/search_controller.php | 43 +++++++++++++++++++++++++++++++++++++--
 models/parallel_model.php         |  9 +++++++-
 2 files changed, 49 insertions(+), 3 deletions(-)

diff --git a/controllers/search_controller.php b/controllers/search_controller.php
index 3378a32..ff12718 100755
--- a/controllers/search_controller.php
+++ b/controllers/search_controller.php
@@ -985,6 +985,9 @@ class SearchController extends Controller implements CrawlConstants
     {
         global $CACHE, $IMAGE_TYPES;
 
+        $flag = 0;
+        $crawl_item = null;
+
         $hash_key = crawlHash(
             $terms.$url.serialize($highlight).serialize($crawl_time));
         if(USE_CACHE) {
@@ -997,8 +1000,44 @@ class SearchController extends Controller implements CrawlConstants
         if($crawl_time == 0) {
             $crawl_time = $this->crawlModel->getCurrentIndexDatabaseName();
         }
-        $this->phraseModel->index_name = $crawl_time;
-        $this->crawlModel->index_name = $crawl_time;
+
+        //Get all crawl times
+        $crawl_times = array();
+        $all_crawl_details = $this->crawlModel->getCrawlList();
+        foreach($all_crawl_details as $crawl_details){
+            if($crawl_details['CRAWL_TIME'] !== null){
+                array_push($crawl_times,$crawl_details['CRAWL_TIME']);
+            }
+        }
+        for($i=0; $i < count($crawl_times); $i++){
+            $crawl_times[$i] = intval($crawl_times[$i]);
+        }
+        asort($crawl_times);
+
+        //Get int value of current crawl time for comparison
+        $crawl_time_int = intval($crawl_time);
+
+        /*Search for the nearest future crawl time containing the cached 
+          version of the page for $url*/
+        foreach($crawl_times as $time){
+            if($time >= $crawl_time_int){
+
+                $crawl_time = (string)$time;
+
+                $this->phraseModel->index_name = $crawl_time;
+                $this->crawlModel->index_name = $crawl_time;
+
+                $crawl_item = $this->crawlModel->
+                    getCrawlItem($url, $queue_servers);
+
+                if($crawl_item !== false){
+                    $flag = 1;
+                    break;
+                } else {
+                    continue;
+                }
+            }
+        }
 
         $data = array();
 
diff --git a/models/parallel_model.php b/models/parallel_model.php
index 4a5d6d0..c6a4d84 100755
--- a/models/parallel_model.php
+++ b/models/parallel_model.php
@@ -238,6 +238,8 @@ class ParallelModel extends Model implements CrawlConstants
      */
     function nonNetworkGetCrawlItems($lookups)
     {
+        $summary_offset = null;
+        $generation = null;
         $summaries = array();
         $db = $this->db;
         $db->selectDB(DB_NAME);
@@ -245,8 +247,13 @@ class ParallelModel extends Model implements CrawlConstants
             if(count($lookup_info) == 2 && $lookup_info[0][0] === 'h') {
                 list($url, $index_name) = $lookup_info;
                 $index_archive = IndexManager::getIndex($index_name);
-                list($summary_offset, $generation) = 
+                $offset_gen_arr = 
                     $this->lookupSummaryOffsetGeneration($url, $index_name);
+                if($offset_gen_arr !== false){
+                    list($summary_offset, $generation) = $offset_gen_arr;
+                } else {
+                    return false;
+                }
                 $summary = 
                     $index_archive->getPage($summary_offset, $generation);
             } else {
-- 
1.7.11.msysgit.1

