Skip to content

Commit

Permalink
Fixes issue Seneca-CDOT#462
Browse files Browse the repository at this point in the history
  • Loading branch information
c3ho committed Feb 6, 2020
1 parent 4260501 commit c6f9f11
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/backend/data/feed.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const normalizeUrl = require('normalize-url');

const { getFeed, addFeed } = require('../utils/storage');
const { getFeed, addFeed, addInvalidFeed } = require('../utils/storage');
const hash = require('./hash');

const urlToId = url => hash(normalizeUrl(url));
Expand Down Expand Up @@ -30,6 +30,10 @@ class Feed {
addFeed(this);
}

saveInvalid() {
addInvalidFeed(this);
}

/**
* Creates a Feed by extracting data from the given feed-like object.
* @param {Object} o - an Object containing the necessary fields for a feed
Expand Down
17 changes: 17 additions & 0 deletions src/backend/utils/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const { redis } = require('../lib/redis');
// Redis Keys
const feedsKey = 't:feeds';
const postsKey = 't:posts';
const invalidKey = 't:feeds:invalid';

// Namespaces
const feedNamespace = 't:feed:';
Expand Down Expand Up @@ -47,6 +48,22 @@ module.exports = {

getFeedsCount: () => redis.scard(feedsKey),

addInvalidFeed: async feed => {
const key = createFeedKey(feed.id);
await redis
.multi()
// Using hmset() until hset() fully supports multiple fields:
// https://github.com/stipsan/ioredis-mock/issues/345
// https://github.com/luin/ioredis/issues/551
.hmset(key, 'id', feed.id, 'author', feed.author, 'url', feed.url)
.sadd(invalidKey, feed.id)
.exec();
},

getInvalidFeeds: () => redis.smembers(invalidKey),

getInvalidCount: () => redis.scard(invalidKey),

/**
* Posts
*/
Expand Down

0 comments on commit c6f9f11

Please sign in to comment.