1
0
Fork 0

Run DB writes sequentially to avoid deadlocks

This commit is contained in:
Gregory Eremin 2015-03-21 21:18:41 +07:00
parent 6a35467c1e
commit 8e779f76ec
4 changed files with 11 additions and 11 deletions

View File

@ -27,14 +27,14 @@ func Authenticate(code string) (token, login string, err error) {
} }
login = user.Login login = user.Login
log.Println("Saving user", user) log.Println("Saving user", user)
user.Save() db.Queue(func() { user.Save() })
tok := &db.Token{ tok := &db.Token{
User: login, User: login,
Token: token, Token: token,
} }
log.Println("Saving token", tok) log.Println("Saving token", tok)
tok.Save() db.Queue(func() { tok.Save() })
return return
} }

View File

@ -31,7 +31,7 @@ func SyncRepos(token, owner string) {
IsPrivate: *repo.Private, IsPrivate: *repo.Private,
IsFork: *repo.Fork, IsFork: *repo.Fork,
} }
r.Save() db.Queue(func() { r.Save() })
} }
if opt.Page >= resp.LastPage { if opt.Page >= resp.LastPage {
break break
@ -67,7 +67,7 @@ func SyncContrib(token, owner string, repo *db.Repo) {
Additions: *week.Additions, Additions: *week.Additions,
Deletions: *week.Deletions, Deletions: *week.Deletions,
} }
c.Save() db.Queue(func() { c.Save() })
} }
} }
} }
@ -102,7 +102,7 @@ func SyncUserOrgs(token string) (err error) {
} }
go SyncOrgTeams(token, o) go SyncOrgTeams(token, o)
go SyncOrgMembers(token, o) go SyncOrgMembers(token, o)
o.Save() db.Queue(func() { o.Save() })
} }
if opt.Page >= resp.LastPage { if opt.Page >= resp.LastPage {
break break
@ -136,7 +136,7 @@ func SyncOrgTeams(token string, org *db.Org) (err error) {
} }
go SyncTeamMembers(token, t) go SyncTeamMembers(token, t)
go SyncTeamRepos(token, t) go SyncTeamRepos(token, t)
t.Save() db.Queue(func() { t.Save() })
} }
if opt.Page >= resp.LastPage { if opt.Page >= resp.LastPage {
break break
@ -169,7 +169,7 @@ func SyncOrgMembers(token string, org *db.Org) (err error) {
break break
} }
} }
db.SaveOrgMembers(org.ID, ids) db.Queue(func() { db.SaveOrgMembers(org.ID, ids) })
return return
} }
@ -196,7 +196,7 @@ func SyncTeamMembers(token string, team *db.Team) (err error) {
break break
} }
} }
db.SaveTeamMembers(team.OrgID, team.ID, ids) db.Queue(func() { db.SaveTeamMembers(team.OrgID, team.ID, ids) })
return return
} }
@ -223,7 +223,7 @@ func SyncTeamRepos(token string, team *db.Team) (err error) {
break break
} }
} }
db.SaveTeamRepos(team.OrgID, team.ID, ids) db.Queue(func() { db.SaveTeamRepos(team.OrgID, team.ID, ids) })
return return
} }

View File

@ -26,7 +26,7 @@ func saveResponseMeta(token string, res *github.Response) {
Remaining: res.Remaining, Remaining: res.Remaining,
ResetAt: res.Reset.Time, ResetAt: res.Reset.Time,
} }
tok.Save() db.Queue(func() { tok.Save() })
} }
func report(task string, start time.Time) { func report(task string, start time.Time) {

View File

@ -42,7 +42,7 @@ func SyncUserInfo(token, login string) (err error) {
defer report("SyncUserInfo", time.Now()) defer report("SyncUserInfo", time.Now())
var u *db.User var u *db.User
if u, err = FetchUserInfo(token, login); err == nil { if u, err = FetchUserInfo(token, login); err == nil {
u.Save() db.Queue(func() { u.Save() })
} }
return return
} }