bnoguchi/everyauth — Issue #144: findUserById is getting called 21 times!
Author: andrewtennison
Created: 2011-12-30 19:54:15+00:00
State: open

everyauth.everymodule.findUserById is getting called 21 times for one page load, which will obviously result in 20 unnecessary API calls.

I have gone through the code and created local vars to cache the user object in all the obvious places but this has not solved the issue. From console.logs it appears to be when res.render gets called, but having also created a local var in the view for everyauth.user it does not appear to be this.

Oddly after more research it does not appear to be the view template causing this, not sure what happens after a view is rendered that might cause this.

Wondering if you are aware of any issue that may cause this?

The code -

```javascript
// server,js
app.get('/', routes.index);

// routes/index.js
exports.index = function(req, res){
var user = req.user;
if(req.loggedIn){
console.log('routes.index, user enabled + logged in, preload content, req.user = ');
res.render('pages/index', {title: 'Onside', cssPath: '', jsPath:'', channels: [], events: [], searches: [] });
} else {
res.render('pages/signup.ejs', { title: 'Onside', cssPath: '.signup', jsPath:'.signup', loggedIn:false })
}
};

```