我认为我的音乐应用程序的架构设计有问题。
我有 3 个集合Artists
:Tracks
和Albums
。和 3 类artists
:albums
和tracks
文件来自artists
:
[_id] => MongoId Object
(
[$id] => 4ee5bbfd615c219a07000000
)
[freeze] => false,
[genres] => Array,
[hits] => 0,
[name] => Sarya Al Sawas,
[pictures] => Array,
文件来自albums
:
[_id] => MongoId Object
(
[$id] => 4ee88308615c218128000000
)
[name] => Sabia
[slug] => wafiq-habib-ft-sarya-al-sawas-sabia
[year] => 1999
[genres] => Array,
[pictures] => Array,
[artists] => Array
(
[0] => MongoId Object
(
[$id] => 4ee34a3b615c21b624010000
)
[1] => MongoId Object
(
[$id] => 4ee5bbfd615c219a07000000
)
)
文件来自tracks
[_id] => MongoId Object
(
[$id] => 4ee8a056615c21542a000000
)
[name] => Bid Ashok
[slug] => wafiq-habib-ft-sarya-al-sawas-bid-ashok
[genres] => Array,
[file] => /m/tracks/t.4ee8a05540c624.04707814.mp3,
[freeze] => false,
[hits] => 0,
[duration] => 303,
[albums] => Array
(
[0] => MongoId Object
(
[$id] => 4ee5cbc3615c216509000000
)
)
[artists] => Array
(
[0] => MongoId Object
(
[$id] => 4ee5bbfd615c219a07000000
)
[1] => MongoId Object
(
[$id] => 4ee34a3b615c21b624010000
)
)
首先是好的架构设计??!我这样设计这个模式是因为多对多的关系,有时曲目有 2 位艺术家,而专辑有 2 位艺术家。
无论如何,我在查询附加到特定曲目的专辑时遇到问题。
假设我在艺术家页面上
我需要获取所有艺术家的专辑和曲目,所以我这样做:
$cursors = array( 'albums' => $this->albums->find(array('artists' => $artist->_id))->sort(array('_id' => -1)), 'tracks' => $this->tracks->find(array('artists' => $artist->_id))->sort(array('_id' => -1)), 'clips' => $this->clips->find(array('artists' => $artist->_id))->sort(array('_id' => -1)) ); foreach($cursors as $key => $cursor) { foreach($cursor as $obj) { $obj['name'] = ($this->lang->get() != 'ar' ? $obj['translated']['name'] : $obj['name']); $obj['by'] = $this->artists()->get($obj['artists'])->toString('ft'); ${$key}[] = $obj; } }
我需要循环播放所有曲目并获取他们的专辑名称假设这位艺术家有 3000 首曲目我认为这会很慢......
所以我的问题是:这是一个好的架构设计吗?