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会更好吗?