DengTao 8 years ago
parent
commit
119adee779
2 changed files with 5 additions and 17 deletions
  1. 5 16
      www/protected/commands/getPetUserWorkCommand.php
  2. 0 1
      www/protected/data/petUser.json

+ 5 - 16
www/protected/commands/getPetUserWorkCommand.php

@@ -13,33 +13,23 @@ class GetPetUserWorkCommand extends CConsoleCommand{
         set_time_limit(0);
         $this->getPetUser();
 
+
     }
 
     public function getPetUser(){
 
         $m = new MongoClient(DB_CONNETC);
         $count = 0;
-        $last_index = 0;
         $collection = $m->selectCollection('cute','pet_user');
-
-        $myfile =  file_get_contents(dirname(__FILE__).'/../data/petUser.json');
-
-        if(!empty($myfile)){
-            $myfile = json_decode($myfile,true);
-            $index = intval($myfile['last_index']);
-        } else {
-            $cursor = $collection->find();
-            $cursor->sort(array('id' => -1));
-            $index = $cursor->getNext()['id'];
-            self::writeLastIndex($index);
-        }
+        $cursor = $collection->find();
+        $cursor->sort(array('id' => -1));
+        $index = $cursor->getNext()['id'];
         if (empty($index)){
             $index = 1;
         }
 
         while($index) {
-            if($count>= 1000){
-                self::writeLastIndex($last_index);
+            if($count>= 50){
                 exit;
             }
             $count++;
@@ -68,7 +58,6 @@ class GetPetUserWorkCommand extends CConsoleCommand{
 
                     }
                     $collection->insert($data);
-                    $last_index =$data['id'];
                 }
             }
             sleep(3);

+ 0 - 1
www/protected/data/petUser.json

@@ -1 +0,0 @@
-{"last_index":1001}