-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tab on user profile to show starred repos #181
Conversation
Current coverage is 3.02% (diff: 0.00%)@@ master #181 diff @@
========================================
Files 33 34 +1
Lines 8106 8119 +13
Methods 0 0
Messages 0 0
Branches 0 0
========================================
Hits 246 246
- Misses 7840 7853 +13
Partials 20 20
|
_, err = x.Exec("UPDATE `user` SET num_stars = num_stars - 1 WHERE id = ?", userID) | ||
} | ||
return err | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think all the SQL should be executed in one transaction.
if setting.UsePostgreSQL { | ||
sess = sess.Join("LEFT", "star", `"user".id = star.uid`) | ||
} else { | ||
sess = sess.Join("LEFT", "star", "user.id = star.uid") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just use
sess.Join("LEFT", "star", "`user`.id = star.uid")
is OK.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lunny Both of your suggestions was not in code I touched. I just moved it from another file. I only wrote the last function.
Should I fix it in this PR or another one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both are OK.
LGTM |
} | ||
|
||
// Star or unstar repository. | ||
func StarRepo(userID, repoID int64, star bool) (err error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
golint error
"code.gitea.io/gitea/modules/setting" | ||
) | ||
|
||
type Star struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
golint error
return has | ||
} | ||
|
||
func (repo *Repository) GetStargazers(page int) ([]*User, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
golint
return users, sess.Find(&users) | ||
} | ||
|
||
func (u *User) GetStarredRepos(private bool) (repos []*Repository, err error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
golint
@lunny Updated |
sess.Rollback() | ||
return err | ||
} | ||
if _, err := x.Exec("UPDATE `repository` SET num_stars = num_stars + 1 WHERE id = ?", repoID); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sess.
sess.Rollback() | ||
return err | ||
} | ||
if _, err := x.Exec("UPDATE `user` SET num_stars = num_stars + 1 WHERE id = ?", userID); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sess.
return nil | ||
} | ||
|
||
if _, err := x.Delete(&Star{0, userID, repoID}); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sess.
sess.Rollback() | ||
return err | ||
} | ||
if _, err := x.Exec("UPDATE `repository` SET num_stars = num_stars - 1 WHERE id = ?", repoID); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sess.
sess.Rollback() | ||
return err | ||
} | ||
if _, err := x.Exec("UPDATE `user` SET num_stars = num_stars - 1 WHERE id = ?", userID); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sess.
@lunny You was right. Fixed now. |
// StarRepo or unstar repository. | ||
func StarRepo(userID, repoID int64, star bool) error { | ||
sess := x.NewSession() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
defer sess.Close()
This must be called and sess.Rollback will be invoked in Close if Commit will not be invoked.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lunny Updated
Deprecated in favor of #519 |
Improvements pending for future PRs: