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

Commit

Permalink
如果题库题目不包含时间,不覆盖本地题库
Browse files Browse the repository at this point in the history
  • Loading branch information
sundy-li committed Jan 13, 2018
1 parent 1ab3eb8 commit d7456c1
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions db.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func FetchQuestion(question *Question) (str string) {
memoryDb.View(func(tx *bolt.Tx) error {
b := tx.Bucket([]byte(QuestionBucket))
v := b.Get([]byte(question.Data.Quiz))
q := DecodeQuestionCols(v)
q := DecodeQuestionCols(v, time.Now().Unix())
str = q.Answer
return nil
})
Expand All @@ -56,7 +56,7 @@ func FetchQuestionTime(quiz string) (res int64) {
memoryDb.View(func(tx *bolt.Tx) error {
b := tx.Bucket([]byte(QuestionBucket))
v := b.Get([]byte(quiz))
q := DecodeQuestionCols(v)
q := DecodeQuestionCols(v, time.Now().Unix())
res = q.Update
return nil
})
Expand Down Expand Up @@ -109,7 +109,7 @@ func MergeQuestions(fs ...string) {
memoryDb.Update(func(tx *bolt.Tx) error {
b := tx.Bucket([]byte(QuestionBucket))
//三方包的时间
q := DecodeQuestionCols(v)
q := DecodeQuestionCols(v, 0)
//数据库中的时间
if q.Update > FetchQuestionTime(string(k)) {
b.Put(k, q.GetData())
Expand All @@ -136,13 +136,14 @@ func NewQuestionCols(answer string) *QuestionCols {
}
}

func DecodeQuestionCols(bs []byte) *QuestionCols {
func DecodeQuestionCols(bs []byte, update int64) *QuestionCols {
var q = &QuestionCols{}
err := json.Unmarshal(bs, q)
if err == nil {
return q
} else {
q = NewQuestionCols(string(bs))
q.Update = update
}
return q
}
Expand Down

0 comments on commit d7456c1

Please sign in to comment.