feat(home): show albums list by push time

This commit is contained in:
OldHawk
2018-05-23 17:08:44 +08:00
parent 4428f4434a
commit 955e35fe5b
2 changed files with 9 additions and 1 deletions

View File

@@ -169,6 +169,7 @@ exports.toggleHomeItemStatus = function (req, res) {
var album = req.album;
album.isHomeStatus = !album.isHomeStatus;
album.home_at = Date.now();
album.save(function (err) {
if (err) {
@@ -206,6 +207,8 @@ exports.list = function (req, res) {
var isHomeStatus = undefined;
var condition = {};
var sort_str = '-recommend_level -ordered_at -created_at';
if (req.query.type !== undefined) {
type = req.query.type;
}
@@ -218,13 +221,14 @@ exports.list = function (req, res) {
}
if (isHomeStatus !== undefined) {
condition.isHomeStatus = isHomeStatus;
sort_str = '-home_at';
}
mtDebug.info(condition);
var findQuery = function (callback) {
Album.find(condition)
.sort('-recommend_level -ordered_at -created_at')
.sort(sort_str)
.populate('torrents')
.exec(function (err, albums) {
if (err) {

View File

@@ -51,6 +51,9 @@ var AlbumSchema = new Schema({
type: Boolean,
default: false
},
home_at: {
type: Date,
},
created_at: {
type: Date,
default: Date.now
@@ -62,5 +65,6 @@ var AlbumSchema = new Schema({
}, {usePushEach: true});
AlbumSchema.index({type: 1, recommend_level: 1, ordered_at: -1, created_at: -1});
AlbumSchema.index({isHomeStatus: 1, home_at: -1});
mongoose.model('Album', AlbumSchema);