From 1ca70ebbd06f8e17077c64be790bf698cbd3d93f Mon Sep 17 00:00:00 2001 From: Paul Sori Date: Sun, 7 Oct 2018 03:20:23 -0400 Subject: [PATCH] remove useless caching --- docs/API/db_album-songs.md | 4 -- docs/API/shared_make-shared.md | 9 +---- modules/config/configure-json-file.js | 1 - modules/db-read/database-public-loki.js | 51 ++----------------------- 4 files changed, 5 insertions(+), 60 deletions(-) diff --git a/docs/API/db_album-songs.md b/docs/API/db_album-songs.md index 3f36df9..d6def1b 100644 --- a/docs/API/db_album-songs.md +++ b/docs/API/db_album-songs.md @@ -47,7 +47,3 @@ ... ] ``` - -* **TODO** - - An `artist` param should be added to avoid problems with duplicate album names diff --git a/docs/API/shared_make-shared.md b/docs/API/shared_make-shared.md index 2e482f6..d412bd1 100644 --- a/docs/API/shared_make-shared.md +++ b/docs/API/shared_make-shared.md @@ -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' + ``` \ No newline at end of file diff --git a/modules/config/configure-json-file.js b/modules/config/configure-json-file.js index b266c6c..d5b59c8 100644 --- a/modules/config/configure-json-file.js +++ b/modules/config/configure-json-file.js @@ -1,7 +1,6 @@ const fs = require('fs'); exports.setup = function (loadJson) { - // TODO REDO THIS WHOLE THING var errorArray = []; // Check for port diff --git a/modules/db-read/database-public-loki.js b/modules/db-read/database-public-loki.js index 09faf01..e2de13a 100644 --- a/modules/db-read/database-public-loki.js +++ b/modules/db-read/database-public-loki.js @@ -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);