Permalink
Browse files

Refresh the subscription list after adding a new feed

Allow the UI to see the results of the first fetch without having to
wait until the next one.
  • Loading branch information...
lovett committed Oct 24, 2018
1 parent 143e030 commit dbacfe44a11f3ddebaee52e2994d4f79a11bb932
Showing with 16 additions and 3 deletions.
  1. +1 −0 dispatcher/feed/subscribed.js
  2. +1 −0 schema/001.sql
  3. +14 −3 ui/models/Subscription.js
@@ -30,6 +30,7 @@ module.exports = function (userId, callback = () => {}) {
`SELECT coalesce(u.title, f.title) as title, f.id, f.url, f.siteUrl,
count(ue.entryId) as entryCount,
CAST(strftime('%s', f.created) AS INTEGER) as created,
CAST(strftime('%s', u.created) AS INTEGER) as subscribed,
CAST(strftime('%s', f.nextFetch) AS INTEGER) as nextFetch,
(SELECT CAST(strftime('%s', fs.created) AS INTEGER)
FROM fetchStats fs
@@ -63,6 +63,7 @@ CREATE TABLE IF NOT EXISTS userFeeds
(
userId INTEGER NOT NULL,
feedId INTEGER NOT NULL,
created DEFAULT CURRENT_TIMESTAMP,
title TEXT DEFAULT NULL,
FOREIGN KEY(userId) REFERENCES users(id) ON DELETE CASCADE,
FOREIGN KEY(feedId) REFERENCES feeds(id) ON DELETE CASCADE,
@@ -63,10 +63,21 @@ export default {
return;
}

// Fetch if a feed has just been added.
const newlyAdded = this.feeds.some((feed) => {
const age = Math.abs(feed.subscribed - Date.now()/1000);
return feed.entryCount === 0 && age < 20;
});

if (newlyAdded) {
this.load();
return;
}

// Fetch if any feeds have passed their nextFetch date.
const stale = this.feeds.some((feed) => {
if (feed.nextFetch < this.fetchedOn) {
console.log(`{$feed.title} is supposed to be fetched on ${new Date(feed.fetchedOn)} but the last fetch by the ui was ${new Date(this.fetchedOn)} so the feed is stale`);
console.log(`${feed.title} is supposed to be fetched on ${new Date(feed.nextFetch)} but the last fetch by the ui was ${new Date(this.fetchedOn)} so the feed is stale`);
}
return feed.nextFetch < this.fetchedOn;
});
@@ -87,8 +98,8 @@ export default {
withCredentials: true
}).then((res) => {
this.load();
Subscription.adding = false;
Subscription.editing = false;
this.adding = false;
this.editing = false;
}).catch((e) => {
console.log(e);
});

0 comments on commit dbacfe4

Please sign in to comment.