0
在我們的應用程序中,我們有5個表,使用ContentProvider從REST服務更新。
內容提供者和數據庫視圖
- 照片
- 狀態
- 喜歡
- 評論
- 用戶
我們使用ContentProvider的爲我們所有的數據庫相關的電話,我們想要實現一個像Activity一樣的feed h具有擴展CursorAdapter的適配器的ListView。
我們的飼料應顯示無論是照片還是狀態,其中對於每一個照片/狀態的項目有顯示:
- 項目的創建者的用戶名
- 項目的喜好
- 項目的數數評論
我們考慮使用視圖
實現它210CREATE VIEW event_feed AS
select * from (
select "Photo" as type, p.*, u.*,
(select count(*) from comments where subjectId = p.id) comment_count,
(select count(*) from likes where subjectId = p.id) like_count
from photos p inner join users u on p.creatorId = u.id
union
select "Status" as type, s.*, u.*,
(select count(*) from comments where subjectId = s.id) comment_count,
(select count(*) from likes where subjectId = s.id) like_count
from statuses s inner join users u on s.creatorId = u.id
)
order by createdAt desc
創建後,我們將查詢使用ContentProvider的一個光標
問題
- 性能方面來看,有沒有更好的辦法?
- CursorJoiner會更好嗎?