Skip to content

Commit c8ca728

Browse files
committed
Docs: Add two new faq for the selected site usage and site id convention
Question.1: Should I use 'AppPrefs' or 'SelectedSiteRepository' as the source of truth on a selected site? Question.2: Should I use 'id', 'siteId', 'siteLocalId', 'siteRemoteId' or any other naming convention?
1 parent 92e840e commit c8ca728

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

docs/faq.md

+32-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,35 @@
33
#### I can't build/test/package the project because of a `PermGen space` error.
44

55
Create a `gradle.properties` file in the project root directory with the
6-
following: `org.gradle.jvmargs=-XX:MaxPermSize=1024m`.
6+
following: `org.gradle.jvmargs=-XX:MaxPermSize=1024m`.
7+
8+
#### Should I use `AppPrefs` or `SelectedSiteRepository` as the source of truth on a selected site?
9+
10+
The short answer is to always use the `SelectedSiteRepository`, which is the in-memory mechanism.
11+
This should always be your goto class when you want to work with the selected site instance, your
12+
source of truth.
13+
14+
Getting the selected site from `AppPrefs`, which is the persistence mechanism, should only be
15+
limited to specific usages. Below is a complete list of those:
16+
17+
- `WordPress.mUpdateSelectedSite`: Which runs in a background task and updates the site information.
18+
- `WordPress.sanitizeMediaUploadStateForSite()`: Which is being trigger from `onCreate(...)`and
19+
`onAppComesFromBackground()`.
20+
- `UploadService,onMediaUploaded(...)`: Which ensures that the handlers have already received and
21+
processed the incoming `OnMediaUploaded` event.
22+
- `WPMainActivity.initSelectedSite()`: Which is being trigger from multiple place within
23+
`WPMainActivity` itself, including but not limited to `onCreate(...)`, `onResume(...)` and
24+
`onActivityResult(...)`.
25+
26+
#### Should I use `id`, `siteId`, `siteLocalId`, `siteRemoteId` or any other naming convention?
27+
28+
The `SiteModel.mId` is the local id, which is actually an auto-increment database index that gets
29+
generated when sites are being persisted locally. However, this id is getting reset when users
30+
log-out and as such it will NOT be the same for a specific site. As such, when working with such an
31+
`id` you should always name it as `siteLocalId` to avoid any confusion.
32+
33+
The `SimeModel.mSiteId`, is the remote id, which comes from the backend, and it is generated during
34+
site creation. Then, it gets persisted within the local database, next to the local id. This id is
35+
NOT getting reset when users log-out and as such it will always be the same for a specific site, no
36+
matter what. As such, when working with such an `siteId` you should always name it as `siteRemoteId`
37+
to avoid any confusion.

0 commit comments

Comments
 (0)