-
Notifications
You must be signed in to change notification settings - Fork 11
/
engine.go
58 lines (46 loc) · 1.1 KB
/
engine.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Copyright 2014 The Too Authors. All rights reserved.
package too
import "github.com/garyburd/redigo/redis"
type Engine struct {
c redis.Conn
class string
autoUpdateSimilarsAndSuggestions bool
Likes Rater
Dislikes Rater
Similars Similars
Suggestions Suggestions
}
// New returns a new engine for given class connected to Redis server at addr.
func New(url, class string) (*Engine, error) {
c, err := redis.DialURL(url)
if err != nil {
return nil, err
}
e := &Engine{
c: c,
class: class,
autoUpdateSimilarsAndSuggestions: true,
}
e.Likes = Rater{e, "likes", nil}
e.Dislikes = Rater{e, "dislikes", nil}
e.Similars = Similars{e}
e.Suggestions = Suggestions{e}
return e, nil
}
func (e *Engine) DisableAutoUpdateSimilarsAndSuggestions() {
e.autoUpdateSimilarsAndSuggestions = false
}
func (e *Engine) EnableAutoUpdateSimilarsAndSuggestions() {
e.autoUpdateSimilarsAndSuggestions = true
}
func (e Engine) Update(user User) error {
err := e.Similars.update(user)
if err != nil {
return err
}
err = e.Suggestions.update(user)
if err != nil {
return err
}
return nil
}