-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
Sort repositories by watch status #19
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,7 @@ import ( | |
| "fmt" | ||
|
|
||
| "github.com/go-gitea/gitea/modules/log" | ||
| "github.com/go-gitea/gitea/modules/setting" | ||
| ) | ||
|
|
||
| type AccessMode int | ||
|
|
@@ -124,13 +125,20 @@ func (u *User) GetRepositoryAccesses() (map[*Repository]AccessMode, error) { | |
| // GetAccessibleRepositories finds repositories which the user has access but does not own. | ||
| // If limit is smaller than 1 means returns all found results. | ||
| func (user *User) GetAccessibleRepositories(limit int) (repos []*Repository, _ error) { | ||
| sess := x.Where("owner_id !=? ", user.ID).Desc("updated_unix") | ||
| sess := x.Where("owner_id !=? ", user.ID).Desc("uid").Desc("updated_unix") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For a better readability and to get the real line / instruction in case of error, please set one XORM instruction per line eg : or |
||
| if limit > 0 { | ||
| sess.Limit(limit) | ||
| repos = make([]*Repository, 0, limit) | ||
| } else { | ||
| repos = make([]*Repository, 0, 10) | ||
| } | ||
|
|
||
| if setting.UsePostgreSQL { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I really dislike this part to check for the used DB
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It has to be done, PostgreSQL uses different syntax.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But you don't need to do that if you use XORM properly
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would you like to suggest changes? I replicated what @unknwon did previously.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just look at the XORM docs, or maybe @lunny can give you a hint since he's the XORM author ;)
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @tboerger I understand where you are coming from but this style of compensating for PostgreSQL is present throughout the existing codebase. I want to propose this be merged first before optimisations be carried out throughout.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's no need to keep these separate, go for the one PostgreSQL needs, since MySQL and SQLite handles that format as well. |
||
| sess = sess.Join("LEFT", "star", `"repository".id=star.repo_id AND star.uid = ?`, user.ID) | ||
| } else { | ||
| sess = sess.Join("LEFT", "star", "repository.id=star.repo_id AND star.uid = ?", user.ID) | ||
| } | ||
|
|
||
| return repos, sess.Join("INNER", "access", "access.user_id = ? AND access.repo_id = repository.id", user.ID).Find(&repos) | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1450,7 +1450,14 @@ func GetRepositoryByID(id int64) (*Repository, error) { | |
|
|
||
| // GetUserRepositories returns a list of repositories of given user. | ||
| func GetUserRepositories(userID int64, private bool, page, pageSize int) ([]*Repository, error) { | ||
| sess := x.Where("owner_id = ?", userID).Desc("updated_unix") | ||
| sess := x.Where("owner_id = ?", userID).Desc("uid").Desc("updated_unix") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For a better readability and to get the real line / instruction in case of error, please set one XORM instruction per line eg : or |
||
|
|
||
| if setting.UsePostgreSQL { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I really dislike this part to check for the used DB
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It has to be done, PostgreSQL uses different syntax.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But you don't need to do that if you use XORM properly
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would you like to suggest changes? I replicated what @unknwon did previously.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just look at the XORM docs, or maybe @lunny can give you a hint since he's the XORM author ;)
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @tboerger I understand where you are coming from but this style of compensating for PostgreSQL is present throughout the existing codebase. I want to propose this be merged first before optimisations be carried out throughout. |
||
| sess = sess.Join("LEFT", "star", `"repository".id=star.repo_id AND star.uid = ?`, userID) | ||
| } else { | ||
| sess = sess.Join("LEFT", "star", "repository.id=star.repo_id AND star.uid = ?", userID) | ||
| } | ||
|
|
||
| if !private { | ||
| sess.And("is_private=?", false) | ||
| } | ||
|
|
@@ -1467,7 +1474,15 @@ func GetUserRepositories(userID int64, private bool, page, pageSize int) ([]*Rep | |
| // GetUserRepositories returns a list of mirror repositories of given user. | ||
| func GetUserMirrorRepositories(userID int64) ([]*Repository, error) { | ||
| repos := make([]*Repository, 0, 10) | ||
| return repos, x.Where("owner_id = ?", userID).And("is_mirror = ?", true).Find(&repos) | ||
| sess := x.Where("owner_id = ?", userID).And("is_mirror = ?", true).Desc("uid") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For a better readability and to get the real line / instruction in case of error, please set one XORM instruction per line eg : or |
||
|
|
||
| if setting.UsePostgreSQL { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I really dislike this part to check for the used DB
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It has to be done, PostgreSQL uses different syntax.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But you don't need to do that if you use XORM properly
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would you like to suggest changes? I replicated what @unknwon did previously.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just look at the XORM docs, or maybe @lunny can give you a hint since he's the XORM author ;)
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @tboerger I understand where you are coming from but this style of compensating for PostgreSQL is present throughout the existing codebase. I want to propose this be merged first before optimisations be carried out throughout. |
||
| sess = sess.Join("LEFT", "star", `"repository".id=star.repo_id AND star.uid = ?`, userID) | ||
| } else { | ||
| sess = sess.Join("LEFT", "star", "repository.id=star.repo_id AND star.uid = ?", userID) | ||
| } | ||
|
|
||
| return repos, sess.Find(&repos) | ||
| } | ||
|
|
||
| // GetRecentUpdatedRepositories returns the list of repositories that are recently updated. | ||
|
|
||
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.
order by uid descwill disableorder by updated_unix desc.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.
Will it? How do I get it to do an
ORDER BY "uid" desc, "updated_unix" desc?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 mean it will disable on logic not the generated SQL. The code is right.
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.
huh?
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 this seems to be the only thing left to resolve here, how do you get multi-column sort with xorm ?
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.
LGTM then. That's right!
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.
@LefsFlarey @strk seems useless, since UID are never duplicates :)
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.
@bkcsoft good point ! Besides, how does that have to do with "watch status" sorting in the title of this PR ?