opt(mongo): optimization db index

This commit is contained in:
OldHawk
2017-12-26 18:33:22 +08:00
parent b31eb05ba6
commit cf311b3f7a
6 changed files with 35 additions and 23 deletions

View File

@@ -147,7 +147,7 @@ var TopicSchema = new Schema({
}, {usePushEach: true});
TopicSchema.index({forum: 1, isTop: -1, lastReplyAt: -1, createdAt: -1});
TopicSchema.index({isGlobal: 1, forum: -1});
TopicSchema.index({createdAt: -1, isGlobal: 1, forum: -1});
mongoose.model('Topic', TopicSchema);
mongoose.model('Attach', AttachSchema);

View File

@@ -52,6 +52,11 @@ var MessageSchema = new Schema({
}
}, {usePushEach: true});
MessageSchema.index({type: 1, from_user: 1, to_user: 1, updatedat: -1, createdat: -1});
//for countUnread
MessageSchema.index({to_user: 1, type: 1, to_status: 1});
//for countUnread
MessageSchema.index({from_user: 1, type: 1, from_status: 1});
//for messagebox list
MessageSchema.index({updatedat: -1, createdat: -1, type: 1, from_user: 1, to_user: 1});
mongoose.model('Message', MessageSchema);

View File

@@ -148,4 +148,6 @@ PeerSchema.index({torrent: 1, peer_status: 1, last_announce_at: 1, peer_download
PeerSchema.index({user: 1, peer_status: 1, last_announce_at: 1, peer_uploaded: 1});
PeerSchema.index({user: 1, peer_status: 1, last_announce_at: 1, peer_downloaded: 1});
PeerSchema.index({last_announce_at: 1, peer_status: 1, user: 1, peer_uploaded: -1});
mongoose.model('Peer', PeerSchema);

View File

@@ -95,6 +95,7 @@ var TorrentSchema = new Schema({
type: String,
default: '',
trim: true,
unique: true,
required: 'info_hash cannot be blank'
},
torrent_filename: {
@@ -299,13 +300,7 @@ TorrentSchema.methods.globalUpdateMethod = function (cb) {
});
};
TorrentSchema.index({info_hash: 1});
TorrentSchema.index({user: -1, createdat: -1});
TorrentSchema.index({maker: 1, createdat: -1});
TorrentSchema.index({torrent_tmdb_id: 1, createdat: -1});
TorrentSchema.index({torrent_recommended: 1, createdat: -1});
TorrentSchema.index({torrent_sale_status: 1, createdat: -1});
TorrentSchema.index({info_hash: 'hashed'});
TorrentSchema.index({
torrent_sale_status: 1,
@@ -316,27 +311,33 @@ TorrentSchema.index({
user: 1,
torrent_recommended: 1,
orderedat: -1,
createdat: -1,
'_peers.id': 1
createdat: -1
});
TorrentSchema.index({
torrent_status: 1,
orderedat: -1,
createdat: -1,
torrent_type: 1,
torrent_status: 1,
torrent_vip: 1,
torrent_recommended: 1,
orderedat: -1,
createdat: -1,
'_peers.id': 1
});
TorrentSchema.index({
torrent_status: 1,
orderedat: -1,
createdat: -1,
torrent_type: 1,
torrent_vip: 1,
torrent_status: 1,
torrent_recommended: 1
});
TorrentSchema.index({
maker: 1,
orderedat: -1,
createdat: -1
createdat: -1,
torrent_type: 1,
torrent_status: 1,
torrent_vip: 1,
});
mongoose.model('Torrent', TorrentSchema);

View File

@@ -22,6 +22,6 @@ var TraceSchema = new Schema({
}, {usePushEach: true});
TraceSchema.index({createdat: -1});
TraceSchema.index({'content.action': -1});
TraceSchema.index({'content.action': 1, createdat: -1});
mongoose.model('Trace', TraceSchema);

View File

@@ -101,6 +101,7 @@ var UserSchema = new Schema({
},
passkey: {
type: String,
unique: true,
default: ''
},
salt: {
@@ -644,10 +645,13 @@ UserSchema.statics.seed = seed;
UserSchema.index({passkey: 1});
UserSchema.index({email: 1});
UserSchema.index({uptotal: 1});
UserSchema.index({status: 1, uploaded: -1, downloaded: -1, ratio: -1, score: -1});
UserSchema.index({status: 1, downloaded: -1, uploaded: -1, ratio: -1, score: -1});
UserSchema.index({status: 1, score: -1, uploaded: -1, downloaded: -1, ratio: -1});
UserSchema.index({status: 1, ratio: -1, uploaded: -1, downloaded: -1, score: -1});
//for rank list
UserSchema.index({uploaded: -1, downloaded: -1, ratio: -1, score: -1, status: 1});
UserSchema.index({created: -1, status: 1});
UserSchema.index({created: -1, status: 1, roles: 1, isVip: 1});
UserSchema.index({isVip: 1, username: 1, displayName: 1, email: 1, created: -1});
UserSchema.index({roles: 1, username: 1, displayName: 1, email: 1, created: -1});
UserSchema.index({status: 1, username: 1, displayName: 1, email: 1, created: -1});