|
|
@ -1,7 +1,8 @@ |
|
|
|
'use strict'; |
|
|
|
'use strict'; |
|
|
|
|
|
|
|
|
|
|
|
const Mongo = require(__dirname+'/db.js') |
|
|
|
const Mongo = require(__dirname+'/db.js') |
|
|
|
, db = Mongo.client.db('jschan'); |
|
|
|
, db = Mongo.client.db('jschan') |
|
|
|
|
|
|
|
, boardCache = new Map(); |
|
|
|
|
|
|
|
|
|
|
|
module.exports = { |
|
|
|
module.exports = { |
|
|
|
|
|
|
|
|
|
|
@ -11,7 +12,7 @@ module.exports = { |
|
|
|
return db.collection('boards').findOne({ '_id': name }); |
|
|
|
return db.collection('boards').findOne({ '_id': name }); |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
find: (name) => { |
|
|
|
find: () => { |
|
|
|
return db.collection('boards').find({}).toArray(); |
|
|
|
return db.collection('boards').find({}).toArray(); |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
@ -31,9 +32,18 @@ module.exports = { |
|
|
|
return db.collection('boards').deleteMany({}); |
|
|
|
return db.collection('boards').deleteMany({}); |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cache: async () => { |
|
|
|
|
|
|
|
const boards = await module.exports.find(); |
|
|
|
|
|
|
|
for (let i = 0; i < boards.length; i++) { |
|
|
|
|
|
|
|
const board = boards[i]; |
|
|
|
|
|
|
|
boardCache.set(board._id, board); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
exists: async (req, res, next) => { |
|
|
|
exists: async (req, res, next) => { |
|
|
|
|
|
|
|
|
|
|
|
const board = await module.exports.findOne(req.params.board); |
|
|
|
//const board = await module.exports.findOne(req.params.board);
|
|
|
|
|
|
|
|
const board = boardCache.get(req.params.board); |
|
|
|
if (!board) { |
|
|
|
if (!board) { |
|
|
|
return res.status(404).render('404'); |
|
|
|
return res.status(404).render('404'); |
|
|
|
} |
|
|
|
} |
|
|
|