Commit cb1c1601d678f02a7918e594cabf002f401bfd2e
1 parent
74b217ea
Cache lors de la lecture de noms
Showing
2 changed files
with
7 additions
and
5 deletions
Show diff stats
app/controllers/noms.js
... | ... | @@ -5,14 +5,14 @@ var fs = require('fs') |
5 | 5 | var noms = {} |
6 | 6 | |
7 | 7 | noms.get = function (login, cb) { |
8 | - Noms.find({ | |
8 | + Noms.findOne({ | |
9 | 9 | login: login |
10 | 10 | }, function (err, nom) { |
11 | 11 | if (err) { |
12 | 12 | console.error(err) |
13 | 13 | cb(false) |
14 | 14 | } else { |
15 | - if (nom.length >= 1) { | |
15 | + if (nom) { | |
16 | 16 | cb(nom.nom) |
17 | 17 | } else { |
18 | 18 | passwdF = 'config/passwd' |
... | ... | @@ -24,11 +24,14 @@ noms.get = function (login, cb) { |
24 | 24 | stream.pipe(transform) |
25 | 25 | transform.on('data', function (line) { |
26 | 26 | ex = line.split(':') |
27 | - console.log(line) | |
28 | 27 | if (ex[0] == login) { // Si trouvé |
29 | - found = true | |
30 | 28 | stream.close() |
31 | 29 | cb(ex[4]) |
30 | + found = true | |
31 | + Noms.create({ | |
32 | + login: login, | |
33 | + nom: ex[4] | |
34 | + }) | |
32 | 35 | } |
33 | 36 | }) |
34 | 37 | transform.on('end', function () { |
... | ... |
app/routes/api.js