Skip to content
This repository was archived by the owner on Aug 2, 2018. It is now read-only.

Commit d7456c1

Browse files
committed
如果题库题目不包含时间,不覆盖本地题库
1 parent 1ab3eb8 commit d7456c1

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

db.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func FetchQuestion(question *Question) (str string) {
4545
memoryDb.View(func(tx *bolt.Tx) error {
4646
b := tx.Bucket([]byte(QuestionBucket))
4747
v := b.Get([]byte(question.Data.Quiz))
48-
q := DecodeQuestionCols(v)
48+
q := DecodeQuestionCols(v, time.Now().Unix())
4949
str = q.Answer
5050
return nil
5151
})
@@ -56,7 +56,7 @@ func FetchQuestionTime(quiz string) (res int64) {
5656
memoryDb.View(func(tx *bolt.Tx) error {
5757
b := tx.Bucket([]byte(QuestionBucket))
5858
v := b.Get([]byte(quiz))
59-
q := DecodeQuestionCols(v)
59+
q := DecodeQuestionCols(v, time.Now().Unix())
6060
res = q.Update
6161
return nil
6262
})
@@ -109,7 +109,7 @@ func MergeQuestions(fs ...string) {
109109
memoryDb.Update(func(tx *bolt.Tx) error {
110110
b := tx.Bucket([]byte(QuestionBucket))
111111
//三方包的时间
112-
q := DecodeQuestionCols(v)
112+
q := DecodeQuestionCols(v, 0)
113113
//数据库中的时间
114114
if q.Update > FetchQuestionTime(string(k)) {
115115
b.Put(k, q.GetData())
@@ -136,13 +136,14 @@ func NewQuestionCols(answer string) *QuestionCols {
136136
}
137137
}
138138

139-
func DecodeQuestionCols(bs []byte) *QuestionCols {
139+
func DecodeQuestionCols(bs []byte, update int64) *QuestionCols {
140140
var q = &QuestionCols{}
141141
err := json.Unmarshal(bs, q)
142142
if err == nil {
143143
return q
144144
} else {
145145
q = NewQuestionCols(string(bs))
146+
q.Update = update
146147
}
147148
return q
148149
}

0 commit comments

Comments
 (0)