Skip to content

Commit

Permalink
增加主题置顶字段及查询
Browse files Browse the repository at this point in the history
  • Loading branch information
Jimmy Kuu committed Oct 22, 2014
1 parent 5c2a19c commit 967a484
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/gopher/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import (
"fmt"
"html/template"
"io/ioutil"
"log"
"os"
"runtime"
"log"

"github.com/bradrydzewski/go.auth"
)
Expand Down
1 change: 1 addition & 0 deletions src/gopher/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ type Topic struct {
NodeId bson.ObjectId
LatestReplierId string
LatestRepliedAt time.Time
IsTop bool `bson:"is_top"` // 置顶
}

// 主题所属节点
Expand Down
16 changes: 16 additions & 0 deletions src/gopher/topic.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,20 @@ func topicsHandler(handler Handler, conditions bson.M, sort string, url string,

c = handler.DB.C(CONTENTS)

var topTopics []Topic

if page == 1 {
c.Find(bson.M{"is_top": true}).Sort(sort).All(&topTopics)

var objectIds []bson.ObjectId
for _, topic := range topTopics {
objectIds = append(objectIds, topic.Id_)
}
if len(topTopics) > 0 {
conditions["_id"] = bson.M{"$not": bson.M{"$in": objectIds}}
}
}

pagination := NewPagination(c.Find(conditions).Sort(sort), url, PerPage)

var topics []Topic
Expand All @@ -51,6 +65,8 @@ func topicsHandler(handler Handler, conditions bson.M, sort string, url string,
c = handler.DB.C(LINK_EXCHANGES)
c.Find(nil).All(&linkExchanges)

topics = append(topTopics, topics...)

renderTemplate(handler, "index.html", BASE, map[string]interface{}{
"nodes": hotNodes,
"status": status,
Expand Down

0 comments on commit 967a484

Please sign in to comment.