NetNewsWire/Technotes/ArticlesAndStatuses.markdown

37 lines
1.8 KiB
Markdown
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Why Articles and Statuses Are Separate Tables
An `Article` is an immutable struct; an `ArticleStatus` is a mutable object.
In the database (see ArticlesDatabase), theyre stored in two separate tables: `articles` and `statuses`.
The articles table contains the columns youd expect: `articleID`, `title`, `contentHTML`, and so on.
The statuses table contains `articleID`, `read`, `starred`, `userDeleted`, and `dateArrived` columns.
This separation is deliberate. There are two main reasons: syncing, and strange behavior.
## Syncing
When syncing with another service, its entirely likely that the service will report article status information in calls that are separate from calls to retrieve articles.
Thus the app might learn about statuses for articles it hasnt seen yet.
This way the app can store those statuses without having to have their corresponding articles. And then, when the app does download those articles, it has their statuses already in the database.
## Strange Behavior
The articles database periodically deletes old articles that have been read. (In theory. This code has still to be written at this date (28 April 2019).)
However, it retains old statuses for a considerably longer period of time.
The reason for this is the following strange behavior:
* An article with no pubDate appears in a feed.
* Many months pass, and the article is deleted from the database.
* That exact article re-appears in the feed.
With the article deleted — and since it has no pubDate — how can the app tell if this is a new or old article?
Heres how: it still has the status, and the status includes a `dateArrived` property which is in the distant past — and so NetNewsWire knows that its not new but old.
Note that statuses do get deleted eventually, too (in theory) — but thats after a much longer period of time.