Skip to content
This repository has been archived by the owner on Jan 11, 2023. It is now read-only.

Add DecSync plugin #804

Merged
merged 6 commits into from
Dec 3, 2018
Merged

Add DecSync plugin #804

merged 6 commits into from
Dec 3, 2018

Conversation

39aldo39
Copy link
Contributor

This pull request adds a DecSync plugin for synchronization using DecSync. It is based on the local plugin, with some syncing added.

It also adds the possibility for plugins to always use the articleIDs when articles are read, instead of the setFeedRead, setCategoryRead and markAllItemsRead methods. This is needed since DecSync only uses the articleIDs. Moreover, it is not possible to get the IDs from the database, since it can be updated before the plugin method is called. This also may be more correct for other plugins, since there can be new articles between the last sync and the read action, especially when cached actions are used.

Another point as discussed here is that this duplicates some dependencies from the local plugin. Probably the best way is to move them out of the plugin directories.

Copy link
Collaborator

@brendanlong brendanlong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good for the most part! I think the biggest change I want is to not duplicate all of the libraries. I can make that change if you want, although it may be easier for you to do it (there would be a lot of merge conflicts if I do it).

I'm curious what @jangernert would think of removing the option to set an entire category/feed read at the plugin layer and just always setting articles read individually. I think that's basically what most plugins do anyway, and it might make the logic simpler (fewer plugins will need DB access).

src/Backend/Backend.vala Show resolved Hide resolved
public bool alwaysSetReadByID()
{

}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I'm convinced that we should just remove setFeedRead/setCategoryRead/markAllItemsRead and make this new behavior the only option. I'm guessing it would be slower in some cases (if the backend API doesn't support setting a list of articles to read at once), but that's something we should solve with async or threaded requests.

(RSS_MAJOR_VERSION == (major) && RSS_MINOR_VERSION == (minor) && \
RSS_MICRO_VERSION >= (micro)))

#endif /* __RSS_VERSION_H__ */
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you move all of these local dependencies up so they're shared between this plugin and the local plugin? The vala dependencies can just go in the top-level src folder and I think the C libraries can go in the top-level libraries directory.

(I'm really worried that if we copy these, they'll get out of sync with each other)


public Feed? downloadFeed(Soup.Session session, string xmlURL, string feedID, Gee.List<string> catIDs, out string errmsg)
{
errmsg = "";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, you should prefer to throw exceptions instead of setting error parameters. This makes the code simpler and also makes it harder to misuse the API.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the use of dirty practices like these throughout the codebase is still a relic of the time when we had 2 processes talking via dbus =/

if (msg == null)
{
errmsg = @"Couldn't parse feed URL: $xmlURL";
Logger.warning(errmsg);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally if we're returning or throwing an error message, the caller should print it (to avoid duplicate logging).

return;
}
var cat = new Category(catID, catID, 0, 99, CategoryID.MASTER.to_string(), 1);
var list = new Gee.LinkedList<Category>();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use ListUtils.single(cat) to generate a list with one element as efficiently as possible.

(Also, LinkedLists are almost always worse than ArrayLists)


public string uncategorizedID()
{
return "0";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this return CategoryID.MASTER.to_string()?

tagID = (int.parse(m_db.getMaxID("tags", "tagID")) + 1).to_string();

Logger.info("createTag: ID = " + tagID);
return tagID;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm confused about this function since supportTags() is false. This function should probably either return an empty string or throw an exception.

(At some point I want to redo how plugins work so these functions don't even exist unless the plugin advertises supporting them, but for now just not having any logic in them is good enough)

{
if(!m_db.feed_exists(Feed.getURL())) {
var list = new Gee.ArrayList<Feed>();
list.add(Feed);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using ListUtils.single(feed)

feedID = feedURL;

Logger.info(@"addFeed: ID = $feedID");
Feed? Feed = m_utils.downloadFeed(m_session, feedURL, feedID, catIDs, out errmsg);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Variables should be lowercase:

Feed? feed = m_utils.downloadFeed(m_session, feedURL, feedID, catIDs, out errmsg);

@brendanlong
Copy link
Collaborator

This seems to be causing a build failure in CircleCI due to a missing meson.build file:

https://circleci.com/gh/jangernert/FeedReader/632

Also, is any of this easily testable? I'm trying to get more pieces of FeedReader unit-tested, although I admit I don't know how to do async tests yet. If you think any of it can be tested, you can see an example in the Feedbin plugin (TestFeedbin.vala and the last section of the feedbin plugin's meson.build).

@39aldo39
Copy link
Contributor Author

I have implemented most of requested changes. Only the function from localUtils.downloadFeed still uses error messages. Some changes applied to the local backend as well. It is a bit ugly that some code is almost the same as the local backend. But I don't think it is easy to deduplicate it, since there are still some small changes.

The CircleCI build fails since libdecsync is a submodule, which probably isn't cloned.

I do think this plugin is testable, as long writing/reading files is possible. We can then test whether the changes are correctly written/executed.

@brendanlong
Copy link
Collaborator

It is a bit ugly that some code is almost the same as the local backend. But I don't think it is easy to deduplicate it, since there are still some small changes.

Yeah that's fine. The plugins probably shouldn't depend on each other, I just didn't want to libraries they use to be duplicated too.

The CircleCI build fails since libdecsync is a submodule, which probably isn't cloned.

I just created #809 to fix this. If you rebase once that lands on master it should fix it.

I'll review the updated code after work today.

var list = new Gee.ArrayList<Category>();
list.add(cat);
m_db_write.write_categories(list);
m_db_write.write_categories(ListUtils.single(cat));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing these too! I didn't realize this was existing code you had copied.

@brendanlong brendanlong merged commit fd8c55e into jangernert:master Dec 3, 2018
@brendanlong
Copy link
Collaborator

I just got a chance to test this and it seems to work. Thanks for creating this!

@brendanlong
Copy link
Collaborator

I just triggered a v2.6.0 release so this should show up in Flathub soon.

@39aldo39 39aldo39 deleted the decsync branch December 26, 2018 12:40
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
3 participants