1
0
Fork 0

Int should be enough

This commit is contained in:
Gregory Eremin 2015-03-20 22:22:49 +07:00
parent 788b7d7683
commit abd0d96b10
10 changed files with 39 additions and 39 deletions

View File

@ -5,13 +5,13 @@ import (
) )
type Contrib struct { type Contrib struct {
Week uint64 `json:"week"` Week int `json:"week"`
OrgID uint64 `json:"org_id"` OrgID int `json:"org_id"`
RepoID uint64 `json:"repo_id"` RepoID int `json:"repo_id"`
UserID uint64 `json:"user_id"` UserID int `json:"user_id"`
Commits uint64 `json:"commits"` Commits int `json:"commits"`
Additions uint64 `json:"additions"` Additions int `json:"additions"`
Deletions uint64 `json:"deletions"` Deletions int `json:"deletions"`
} }
func (c *Contrib) Save() { func (c *Contrib) Save() {

View File

@ -7,13 +7,13 @@ import (
"time" "time"
) )
func SaveOrgMembers(orgID uint64, members []uint64) { func SaveOrgMembers(orgID int, members []int) {
defer measure("SaveOrgMembers", time.Now()) defer measure("SaveOrgMembers", time.Now())
tx := db.MustBegin() tx := db.MustBegin()
var ids = []string{} var ids = []string{}
for _, id := range members { for _, id := range members {
ids = append(ids, strconv.FormatUint(id, 10)) ids = append(ids, strconv.Itoa(id))
} }
tx.MustExec(fmt.Sprintf(` tx.MustExec(fmt.Sprintf(`
delete from org_members delete from org_members
@ -37,13 +37,13 @@ func SaveOrgMembers(orgID uint64, members []uint64) {
} }
} }
func SaveTeamMembers(orgID, teamID uint64, members []uint64) { func SaveTeamMembers(orgID, teamID int, members []int) {
defer measure("SaveTeamMembers", time.Now()) defer measure("SaveTeamMembers", time.Now())
tx := db.MustBegin() tx := db.MustBegin()
var ids = []string{} var ids = []string{}
for _, id := range members { for _, id := range members {
ids = append(ids, strconv.FormatUint(id, 10)) ids = append(ids, strconv.Itoa(id))
} }
tx.MustExec(fmt.Sprintf(` tx.MustExec(fmt.Sprintf(`
delete from team_members delete from team_members
@ -68,13 +68,13 @@ func SaveTeamMembers(orgID, teamID uint64, members []uint64) {
} }
} }
func SaveTeamRepos(orgID, teamID uint64, repos []uint64) { func SaveTeamRepos(orgID, teamID int, repos []int) {
defer measure("SaveTeamRepos", time.Now()) defer measure("SaveTeamRepos", time.Now())
tx := db.MustBegin() tx := db.MustBegin()
var ids = []string{} var ids = []string{}
for _, id := range repos { for _, id := range repos {
ids = append(ids, strconv.FormatUint(id, 10)) ids = append(ids, strconv.Itoa(id))
} }
tx.MustExec(fmt.Sprintf(` tx.MustExec(fmt.Sprintf(`
delete from team_repos delete from team_repos

View File

@ -5,7 +5,7 @@ import (
) )
type Org struct { type Org struct {
ID uint64 `json:"id"` ID int `json:"id"`
Login string `json:"login"` Login string `json:"login"`
Company string `json:"company"` Company string `json:"company"`
AvatarURL string `json:"avatar_url" db:"avatar_url"` AvatarURL string `json:"avatar_url" db:"avatar_url"`

View File

@ -5,8 +5,8 @@ import (
) )
type Repo struct { type Repo struct {
ID uint64 `json:"id"` ID int `json:"id"`
OrgID uint64 `json:"org_id"` OrgID int `json:"org_id"`
Name string `json:"name"` Name string `json:"name"`
Description string `json:"description"` Description string `json:"description"`
IsPrivate bool `json:"is_private"` IsPrivate bool `json:"is_private"`

View File

@ -5,8 +5,8 @@ import (
) )
type Team struct { type Team struct {
ID uint64 `json:"id"` ID int `json:"id"`
OrgID uint64 `json:"org_id" db:"org_id"` OrgID int `json:"org_id"`
Slug string `json:"slug"` Slug string `json:"slug"`
Name string `json:"name"` Name string `json:"name"`
Permission string `json:"permission"` Permission string `json:"permission"`

View File

@ -5,11 +5,11 @@ import (
) )
type Token struct { type Token struct {
ID uint64 `json:"id"` ID int `json:"id"`
User string `json:"user"` User string `json:"user"`
Token string `json:"token"` Token string `json:"token"`
Quota uint64 `json:"quota"` Quota int `json:"quota"`
Remaining uint64 `json:"remaining"` Remaining int `json:"remaining"`
ResetAt time.Time `json:"reset_at" db:"reset_at"` ResetAt time.Time `json:"reset_at" db:"reset_at"`
CreatedAt time.Time `json:"created_at" db:"created_at"` CreatedAt time.Time `json:"created_at" db:"created_at"`
} }

View File

@ -5,7 +5,7 @@ import (
) )
type User struct { type User struct {
ID uint64 `json:"id"` ID int `json:"id"`
Login string `json:"login"` Login string `json:"login"`
Name string `json:"name"` Name string `json:"name"`
AvatarURL string `json:"avatar_url" db:"avatar_url"` AvatarURL string `json:"avatar_url" db:"avatar_url"`

View File

@ -25,7 +25,7 @@ func SyncRepos(token, owner string) {
descr = *repo.Description descr = *repo.Description
} }
r := &db.Repo{ r := &db.Repo{
OrgID: uint64(*repo.Organization.ID), OrgID: *repo.Organization.ID,
Name: *repo.Name, Name: *repo.Name,
Description: descr, Description: descr,
IsPrivate: *repo.Private, IsPrivate: *repo.Private,
@ -59,13 +59,13 @@ func SyncContrib(token, owner string, repo *db.Repo) {
} }
c := &db.Contrib{ c := &db.Contrib{
Week: uint64(week.Week.Time.Unix()), Week: int(week.Week.Time.Unix()),
OrgID: repo.OrgID, OrgID: repo.OrgID,
RepoID: repo.ID, RepoID: repo.ID,
UserID: uint64(*contrib.Author.ID), UserID: *contrib.Author.ID,
Commits: uint64(*week.Commits), Commits: *week.Commits,
Additions: uint64(*week.Additions), Additions: *week.Additions,
Deletions: uint64(*week.Deletions), Deletions: *week.Deletions,
} }
c.Save() c.Save()
} }
@ -95,7 +95,7 @@ func SyncUserOrgs(token string) (err error) {
avatarURL = *org.AvatarURL avatarURL = *org.AvatarURL
} }
o := &db.Org{ o := &db.Org{
ID: uint64(*org.ID), ID: *org.ID,
Login: *org.Login, Login: *org.Login,
Company: company, Company: company,
AvatarURL: avatarURL, AvatarURL: avatarURL,
@ -128,8 +128,8 @@ func SyncOrgTeams(token string, org *db.Org) (err error) {
for _, team := range teams { for _, team := range teams {
t := &db.Team{ t := &db.Team{
ID: uint64(*team.ID),
Name: *team.Name, Name: *team.Name,
ID: *team.ID,
Slug: *team.Slug, Slug: *team.Slug,
Permission: *team.Permission, Permission: *team.Permission,
OrgID: org.ID, OrgID: org.ID,
@ -151,7 +151,7 @@ func SyncOrgMembers(token string, org *db.Org) (err error) {
client := newGithubClient(token) client := newGithubClient(token)
opt := &github.ListMembersOptions{ListOptions: github.ListOptions{PerPage: 100}} opt := &github.ListMembersOptions{ListOptions: github.ListOptions{PerPage: 100}}
var ids = []uint64{} var ids = []int{}
for { for {
opt.Page++ opt.Page++
var users []github.User var users []github.User
@ -162,7 +162,7 @@ func SyncOrgMembers(token string, org *db.Org) (err error) {
saveResponseMeta(token, resp) saveResponseMeta(token, resp)
for _, user := range users { for _, user := range users {
ids = append(ids, uint64(*user.ID)) ids = append(ids, *user.ID)
go SyncUserInfo(token, *user.Login) go SyncUserInfo(token, *user.Login)
} }
if opt.Page >= resp.LastPage { if opt.Page >= resp.LastPage {
@ -179,7 +179,7 @@ func SyncTeamMembers(token string, team *db.Team) (err error) {
client := newGithubClient(token) client := newGithubClient(token)
opt := &github.ListOptions{PerPage: 100} opt := &github.ListOptions{PerPage: 100}
var ids = []uint64{} var ids = []int{}
for { for {
opt.Page++ opt.Page++
var users []github.User var users []github.User
@ -190,7 +190,7 @@ func SyncTeamMembers(token string, team *db.Team) (err error) {
saveResponseMeta(token, resp) saveResponseMeta(token, resp)
for _, user := range users { for _, user := range users {
ids = append(ids, uint64(*user.ID)) ids = append(ids, *user.ID)
} }
if opt.Page >= resp.LastPage { if opt.Page >= resp.LastPage {
break break
@ -206,7 +206,7 @@ func SyncTeamRepos(token string, team *db.Team) (err error) {
client := newGithubClient(token) client := newGithubClient(token)
opt := &github.ListOptions{PerPage: 100} opt := &github.ListOptions{PerPage: 100}
var ids = []uint64{} var ids = []int{}
for { for {
opt.Page++ opt.Page++
var repos []github.Repository var repos []github.Repository
@ -217,7 +217,7 @@ func SyncTeamRepos(token string, team *db.Team) (err error) {
saveResponseMeta(token, resp) saveResponseMeta(token, resp)
for _, repo := range repos { for _, repo := range repos {
ids = append(ids, uint64(*repo.ID)) ids = append(ids, *repo.ID)
} }
if opt.Page >= resp.LastPage { if opt.Page >= resp.LastPage {
break break

View File

@ -22,8 +22,8 @@ func saveResponseMeta(token string, res *github.Response) {
} }
tok := &db.Token{ tok := &db.Token{
Token: token, Token: token,
Quota: uint64(res.Limit), Quota: res.Limit,
Remaining: uint64(res.Remaining), Remaining: res.Remaining,
ResetAt: res.Reset.Time, ResetAt: res.Reset.Time,
} }
tok.Save() tok.Save()

View File

@ -31,7 +31,7 @@ func FetchUserInfo(token, login string) (u *db.User, err error) {
u = &db.User{ u = &db.User{
Login: *user.Login, Login: *user.Login,
Name: name, Name: name,
ID: uint64(*user.ID), ID: *user.ID,
AvatarURL: avatarURL, AvatarURL: avatarURL,
} }