为什么UPDATE“会话” SET到期= ...在数据库中打开多个连接?

时间:2019-02-21 02:56:08

标签: node.js postgresql passport.js

我注意到,每次登录时刷新Node.js应用程序上的页面时,以下连接都会打开3-4次

UPDATE "session" SET expire = to_timestamp($1) WHERE sid = $2 RETURNING sid
SELECT sess FROM "session" WHERE sid = $1 AND expire >= to_timestamp($2) 

这是正常现象还是将这些查询限制为仅一个连接?

enter image description here

下面是我的app.js文件

var express = require('express');
var app = express();
var bodyParser = require('body-parser');
var passport = require('passport');
var cookieParser = require('cookie-parser');
var session = require('express-session');

const config = {
    host: process.env.DB_HOST,
    port: 5432,
    database: process.env.DATABASE_NAME,
    user: process.env.DATABASE_USER,
    password: process.env.DATABASE_PASSWORD,
    connectionString: process.env.DATABASE_URL,
    ssl: true,
    poolSize: 4,
    poolIdleTimeout: 2000
};

app.use(session({
    secret: 'My Secret Key',
    resave: false,
    saveUninitialized: false,
    store: new (require('connect-pg-simple')(session))({
        conObject: config,
        pruneSessionInterval: 1800
    }),
    cookie: { maxAge: 20000000 }
}));


app.use(bodyParser.urlencoded({ extended: false }))
app.use(cookieParser())

app.use(express.static(path.join(__dirname, 'public')));

app.use(passport.initialize());
app.use(passport.session());

var indexRouter = require('./routes/index');
var loginRouter = require('./routes/login');

app.use('/', indexRouter);
app.use('/login', loginRouter);

app.set('view engine', 'ejs');
app.set('views', 'views');

server.listen(process.env.PORT || 3004, function () {
    console.log(`Listening on ${server.address().port}`);
});

0 个答案:

没有答案