MCPcopy Index your code
hub / github.com/TruthHun/BookStack / Decrease

Method Decrease

models/book_counter.go:79–107  ·  view source on GitHub ↗
(bookId int, isPV bool)

Source from the content-addressed store, hash-verified

77}
78
79func (*BookCounter) Decrease(bookId int, isPV bool) {
80 sc := NewBookCounter()
81 today, _ := strconv.Atoi(time.Now().Format(dateFormat))
82 o := orm.NewOrm()
83 o.QueryTable(sc).Filter("bid", bookId).Filter("day", today).One(sc)
84 if sc.Id == 0 {
85 sc = &BookCounter{
86 Bid: bookId,
87 Day: today,
88 }
89 if isPV {
90 sc.ViewCnt = 1
91 } else {
92 sc.StarCnt = 1
93 }
94 o.Insert(sc)
95 } else {
96 if isPV {
97 if sc.ViewCnt > 0 {
98 sc.ViewCnt -= 1
99 }
100 } else {
101 if sc.StarCnt > 0 {
102 sc.StarCnt -= 1
103 }
104 }
105 o.Update(sc)
106 }
107}
108
109func (m *BookCounter) StarSort(prd period, limit int, withCache ...bool) (books []SortedBook) {
110 return m._sort(prd, limit, "star", withCache...)

Callers 1

StarMethod · 0.95

Calls 3

NewBookCounterFunction · 0.85
InsertMethod · 0.45
UpdateMethod · 0.45

Tested by

no test coverage detected