remove useless caching

This commit is contained in:
Paul Sori 2018-10-07 03:20:23 -04:00
parent d47777dff4
commit 1ca70ebbd0
4 changed files with 5 additions and 60 deletions

View File

@ -47,7 +47,3 @@
...
]
```
* **TODO**
An `artist` param should be added to avoid problems with duplicate album names

View File

@ -35,11 +35,6 @@
```
{
'playlist_id': 'UUID_SRING',
'token': 'TOKEN_STRING',
'experiationdate':'TODO'
'token': 'TOKEN_STRING'
}
```
* **NOTE:**
I got lazy and haven't included the expiration date yet. That's why the value is set to 'TODO'
```

View File

@ -1,7 +1,6 @@
const fs = require('fs');
exports.setup = function (loadJson) {
// TODO REDO THIS WHOLE THING
var errorArray = [];
// Check for port

View File

@ -4,27 +4,12 @@ const winston = require('winston');
// Loki Collections
var filesdb;
var fileCollection = null;
var fileCollection;
var playlistColection;
// vpath Cache
var userMemCache = {};
function updateUserMemCache() {
// The lazy way, just blow it away and let mtream update it as necessary
userMemCache = {};
// TODO: Fill up cache
}
// TODO: Cache by vPath instead of by user
function getAllArtistsForUser(user) {
var artists = [];
// Return the stored value if it exists
if (userMemCache[user.username] && userMemCache[user.username].artists) {
return userMemCache[user.username].artists;
}
if (fileCollection !== null) {
for (let vpath of user.vpaths) {
var results = fileCollection.find({ 'vpath': { '$eq': vpath } });
@ -35,12 +20,6 @@ function getAllArtistsForUser(user) {
}
}
if (!userMemCache[user.username]) {
userMemCache[user.username] = {};
}
userMemCache[user.username].artists = artists;
artists.sort(function (a, b) {
return a.localeCompare(b);
});
@ -50,11 +29,6 @@ function getAllArtistsForUser(user) {
}
function getAllAlbumsForUser(user) {
// Return the stored value if it exists
if (userMemCache[user.username] && userMemCache[user.username].albums) {
return userMemCache[user.username].albums;
}
var albums = [];
if (fileCollection !== null) {
for (let vpath of user.vpaths) {
@ -72,12 +46,6 @@ function getAllAlbumsForUser(user) {
albums.sort(function (a, b) {
return a.name.localeCompare(b.name);
});
if (!userMemCache[user.username]) {
userMemCache[user.username] = {};
}
userMemCache[user.username].albums = albums;
}
return albums;
@ -98,8 +66,6 @@ function loadDB() {
// first time run so add and configure collection with some arbitrary options
playlistColection = filesdb.addCollection("playlists");
}
updateUserMemCache();
});
}
@ -298,18 +264,11 @@ exports.setup = function (mstream, program) {
res.json({ success: true });
});
// TODO: Re-implment search
mstream.post('/db/search', function (req, res) {
res.json({ error: 'search disabled' });
});
mstream.get('/db/artists', function (req, res) {
var artists = { "artists": getAllArtistsForUser(req.user) };
res.json(artists);
});
mstream.post('/db/artists-albums', function (req, res) {
var albums = { "albums": [] };
if (fileCollection !== null) {
@ -350,6 +309,7 @@ exports.setup = function (mstream, program) {
res.json(albums);
});
// TODO: validate input, allow to search albums by LokiID
mstream.post('/db/album-songs', function (req, res) {
var songs = [];
if (fileCollection !== null) {
@ -442,7 +402,7 @@ exports.setup = function (mstream, program) {
// var amount = 1;
// Ignore songs with star rating of 2 or under
var ignoreRating = false;
// Ignore list TODO: Should we do this on the frontend instead ??
// Ignore list
var ignoreList = [];
if (req.body.ignoreList && Array.isArray(req.body.ignoreList)) {
ignoreList = req.body.ignoreList;
@ -479,15 +439,10 @@ exports.setup = function (mstream, program) {
return;
}
// if (amount > count) {
// amount = count;
// }
while (ignoreList.length > count * ignorePercentage) {
ignoreList.shift();
}
var returnThis = { songs: [], ignoreList: [] };
var randomNumber = Math.floor(Math.random() * count);