Files
NetNewsWire/Technotes/ArticlesAndStatuses.markdown
T

38 lines
1.7 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
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), they’re stored in two separate tables: `articles` and `statuses`.
The articles table contains the columns you’d expect: `articleID`, `title`, `contentHTML`, and so on.
The statuses table contains `articleID`, `read`, `starred`, and `dateArrived` columns.
This separation is deliberate. There are two main reasons: syncing, and strange behavior.
## Syncing
When syncing with another service, it’s 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 hasn’t 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.
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?
Here’s how: it still has the status, and the status includes a `dateArrived` property which is in the distant past — and so NetNewsWire knows that it’s not new but old.
Note that statuses do get deleted eventually, too (in theory) — but that’s after a much longer period of time.