Browse Source

Some DESIGN notes

Girish Ramakrishnan 8 years ago
1 changed files with 31 additions and 2 deletions
  1. 31 2

+ 31 - 2

@@ -1,5 +1,34 @@
 MediaModel is the actual model that loads only what is needed
-from the database depending on what the view sees.
+from the database depending on what the view sees. The database
+queries are carried out in a separate thread called the DBReader
+since all db operations in QSql* block.
 MediaScanner scans directories and populates the database. All
-DB write operations reside here.
+DB write operations reside here. MediaScanner runs as a seperate
+thread and only updates what is necessary based on file timestamps.
+1. The DBReader reads in 'pages'. The model requires the data to be
+   sorted (by title, for example). For paged output, one can use
+   OFFSET and LIMIT in sqlite. However, tracking offset correctly
+   is not possible since MediaScanner might change the database in
+   another thread. For example, it detected a new song and added
+   a new item; our offset is out of sync.
+   Instead of tracking offset, we use ORDER by title. For retreiving,
+   the 'next' page, we use WHERE >= title. We use '>=' because multiple
+   songs of the same title can exist across pages. We, hence, also
+   need to check for duplicates. Duplicate tracking is done by having
+   a unique song id for every song.
+2. MediaScanner runs in parallel and makes changes to the database. An
+   event is sent to the MediaModel when any DB operations is performed.
+   Because of threading, the order of delivery of this DB operation event
+   will mix in all possible ways with the DBReader thread.
+   For example, if we have songs A, B, C in the DB. We ask DBReader to read
+   the database. In the meantime, MediaScanner detects a new Song D and inserts
+   it. The DBReader could come back with A,B,C,D or with just A,B,C.
+   To complicate things, MediaScanner could also report arbitrary 'out-of-range'
+   additions like say a file Z which the model is currently not interested in.