php - MongoDb Collection 300K Objects Making an A to Z page -


we have website 300,000 people on - want make page peoples name starts a, b, or c.

the challenge speed.

how set database. make cache collection. use regex or else.

what i've done following;

 $letter = 'a';  $where  = array(); $where['name']  = new mongoregex("/^" . $letter . "/i"); $sort   = array('name' => 1);  if($hasimage){     $where['images.profiles.0'] = array('$exists' => true); }  $fields = array('name' => 1, 'images.profiles' => 1);   $this->mdb->data_people->ensureindex(array('name' => 1, 'images.profiles' => 1), array('background' => true) );  $people = $this->mdb->data_people->find( $where, $fields );  $people = $people->sort( $sort ); $page['total']      = 100; $page['current']    = 1; $page['perpage']    = 20;  if(isset($this->domain->getquery['_page']) && $this->domain->getquery['_page'] > 1){    $page['current'] = $this->domain->getquery['_page']; }  $data['pages'] = $this->pagenavigation->setnavigation((int) $page['total'], (int) $page['perpage'], (int) $page['current'] ); $data['pages']['page'] = $this->domain->menu_reverse[0]; $data['pages']['path'] = $this->domain->path;  $data['data'] = $people->limit($page['perpage'])->skip( ($page['perpage']*($page['current']-1)) ); 

you pretty doing right thing.

you using right regexp since start of string, , mongodb can use name index.

see bottom of page: http://docs.mongodb.org/manual/reference/operator/query/regex/)

i see 2 potential problems (but always: don't premature optimization, you'll code can fine is):


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -