put boards in a map

merge-requests/208/head
fatchan 5 years ago
parent 91e828e768
commit 9792f123d5
  1. 16
      db/boards.js
  2. 3
      models/forms/make-post.js
  3. 2
      server.js

@ -1,7 +1,8 @@
'use strict';
const Mongo = require(__dirname+'/db.js')
, db = Mongo.client.db('jschan');
, db = Mongo.client.db('jschan')
, boardCache = new Map();
module.exports = {
@ -11,7 +12,7 @@ module.exports = {
return db.collection('boards').findOne({ '_id': name });
},
find: (name) => {
find: () => {
return db.collection('boards').find({}).toArray();
},
@ -31,9 +32,18 @@ module.exports = {
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) => {
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) {
return res.status(404).render('404');
}

@ -12,7 +12,7 @@ const uuidv4 = require('uuid/v4')
, simpleMarkdown = require(__dirname+'/../../helpers/markdown.js')
, sanitize = require('sanitize-html')
, sanitizeOptions = {
allowedTags: [ 'span', 'a', 'code', 'em', 'strong' ],
allowedTags: [ 'span', 'a', 'em', 'strong' ],
allowedAttributes: {
'a': [ 'href', 'class' ],
'span': [ 'class' ]
@ -115,7 +115,6 @@ module.exports = async (req, res, next, numFiles) => {
if (Array.isArray(processedFile.geometryString)) {
processedFile.geometryString = processedFile.geometryString[0];
}
files.push(processedFile);
} catch (err) {

@ -20,6 +20,8 @@ const express = require('express')
// let db connect
await Mongo.connect();
const Boards = require(__dirname+'/db/boards.js');
await Boards.cache();
// parse forms and allow file uploads
app.use(bodyParser.urlencoded({extended: true}));

Loading…
Cancel
Save