OLD | NEW |
1 // Copyright 2015 The LUCI Authors. All rights reserved. | 1 // Copyright 2015 The LUCI Authors. All rights reserved. |
2 // Use of this source code is governed under the Apache License, Version 2.0 | 2 // Use of this source code is governed under the Apache License, Version 2.0 |
3 // that can be found in the LICENSE file. | 3 // that can be found in the LICENSE file. |
4 | 4 |
5 package mutate | 5 package mutate |
6 | 6 |
7 import ( | 7 import ( |
8 "github.com/luci/gae/service/datastore" | 8 "github.com/luci/gae/service/datastore" |
9 "github.com/luci/luci-go/appengine/cmd/dm/model" | 9 "github.com/luci/luci-go/appengine/cmd/dm/model" |
10 "github.com/luci/luci-go/appengine/tumble" | 10 "github.com/luci/luci-go/appengine/tumble" |
(...skipping 13 matching lines...) Expand all Loading... |
24 Quest *model.Quest | 24 Quest *model.Quest |
25 AIDs []uint32 | 25 AIDs []uint32 |
26 | 26 |
27 // DoNotMergeQuest causes this mutation to not attempt to merge the Buil
tBy of | 27 // DoNotMergeQuest causes this mutation to not attempt to merge the Buil
tBy of |
28 // Quest. | 28 // Quest. |
29 DoNotMergeQuest bool | 29 DoNotMergeQuest bool |
30 } | 30 } |
31 | 31 |
32 // Root implements tumble.Mutation. | 32 // Root implements tumble.Mutation. |
33 func (e *EnsureQuestAttempts) Root(c context.Context) *datastore.Key { | 33 func (e *EnsureQuestAttempts) Root(c context.Context) *datastore.Key { |
34 » return datastore.Get(c).KeyForObj(&model.Quest{ID: e.Quest.ID}) | 34 » return model.QuestKeyFromID(c, e.Quest.ID) |
35 } | 35 } |
36 | 36 |
37 // RollForward implements tumble.Mutation. | 37 // RollForward implements tumble.Mutation. |
38 func (e *EnsureQuestAttempts) RollForward(c context.Context) (muts []tumble.Muta
tion, err error) { | 38 func (e *EnsureQuestAttempts) RollForward(c context.Context) (muts []tumble.Muta
tion, err error) { |
39 if !e.DoNotMergeQuest { | 39 if !e.DoNotMergeQuest { |
40 » » if _, err = (&MergeQuest{e.Quest}).RollForward(c); err != nil { | 40 » » if _, err = (&MergeQuest{Quest: e.Quest}).RollForward(c); err !=
nil { |
41 return | 41 return |
42 } | 42 } |
43 } | 43 } |
44 | 44 |
45 if len(e.AIDs) > 0 { | 45 if len(e.AIDs) > 0 { |
46 lim := len(e.AIDs) | 46 lim := len(e.AIDs) |
47 if lim > MaxEnsureAttempts { | 47 if lim > MaxEnsureAttempts { |
48 lim = MaxEnsureAttempts + 1 | 48 lim = MaxEnsureAttempts + 1 |
49 } | 49 } |
50 muts = make([]tumble.Mutation, 0, lim) | 50 muts = make([]tumble.Mutation, 0, lim) |
51 for i, aid := range e.AIDs { | 51 for i, aid := range e.AIDs { |
52 if i > MaxEnsureAttempts { | 52 if i > MaxEnsureAttempts { |
53 muts = append(muts, &EnsureQuestAttempts{e.Quest
, e.AIDs[i:], true}) | 53 muts = append(muts, &EnsureQuestAttempts{e.Quest
, e.AIDs[i:], true}) |
54 break | 54 break |
55 } | 55 } |
56 muts = append(muts, &EnsureAttempt{dm.NewAttemptID(e.Que
st.ID, aid)}) | 56 muts = append(muts, &EnsureAttempt{dm.NewAttemptID(e.Que
st.ID, aid)}) |
57 } | 57 } |
58 } | 58 } |
59 | 59 |
60 return | 60 return |
61 } | 61 } |
62 | 62 |
63 func init() { | 63 func init() { |
64 tumble.Register((*EnsureQuestAttempts)(nil)) | 64 tumble.Register((*EnsureQuestAttempts)(nil)) |
65 } | 65 } |
OLD | NEW |