php - Limiting mysql calls for the same information in cakephp -


i'm using cakephp potentially apply framework / php-based environment.

i have blogging platform , people can like, share, comment etc. each of these likes, shares , comments have associated user , means same user requested database many many times different things, running same query:

select `user`.`id`, `user`.`username`, `user`.`fullname`, `user`.`avatar`, `db`.`users` `user` `user`.`id` = 127 

is there way can stop happening, apart caching? or not matter mysql doing same call 5 or more times same information?

thanks

it's cake way - many simple queries , cache them.

check $this->yourmodelname->find() queries - not use recursive or contain options, when take comments data, cake takes related models too (hasmany/belongsto relations in models). can:

  • use $this->loadmodel(yourmodelname); load model on fly
  • use $this->yourmodelname->behaviors->attach('containable'); attach selected models , fields
  • set recursive => -1 data 1 model/table only
  • use own query join option (it can 1 query instead of contain or recursive option)
  • for data user data can storage in session $this->session->write()
  • if use auth component, can auth $this->auth->user('id')
  • always can set models $usetable = false , link models on fly it's not efficient/economic way (especially when have manage project in further time)

Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

How to get multiresult with multicondition in Sql Server -