Skip to content
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

Sort repositories by watch status #19

Closed
wants to merge 4 commits into from
Closed

Sort repositories by watch status #19

wants to merge 4 commits into from

Conversation

ghost
Copy link

@ghost ghost commented Nov 3, 2016

TL;DR

This PR is a feature addition to sort user repositories by their star/favourite status.

Why?

Many times, I find myself with over 20-ish repositories cluttering up my main page when I am only actively maintaining 2-3 repositories. I have always wanted a simple way to sort them thus I decided to code a quick fix to sort the repositories according to whether I starred them.

Note that this PR does not sort repositories based on number of stars but rather if you, the creator, have starred them yourself.

@ghost ghost added the type/enhancement An improvement of existing functionality label Nov 3, 2016
@tboerger tboerger closed this Nov 3, 2016
@tboerger
Copy link
Member

tboerger commented Nov 3, 2016

Please reopen against master.

@tboerger tboerger added invalid and removed type/enhancement An improvement of existing functionality labels Nov 3, 2016
@bkcsoft bkcsoft changed the base branch from develop to master November 4, 2016 04:17
@bkcsoft bkcsoft added type/enhancement An improvement of existing functionality and removed reviewed/invalid labels Nov 4, 2016
@bkcsoft bkcsoft reopened this Nov 4, 2016
@tboerger tboerger added this to the 1.0.0 milestone Nov 4, 2016
if limit > 0 {
sess.Limit(limit)
repos = make([]*Repository, 0, limit)
} else {
repos = make([]*Repository, 0, 10)
}

if setting.UsePostgreSQL {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really dislike this part to check for the used DB

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It has to be done, PostgreSQL uses different syntax.

Copy link
Member

Choose a reason for hiding this comment

The 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

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you like to suggest changes? I replicated what @unknwon did previously.

Copy link
Member

Choose a reason for hiding this comment

The 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 ;)

Copy link
Author

Choose a reason for hiding this comment

The 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.

Copy link
Member

Choose a reason for hiding this comment

The 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 := x.Where("owner_id = ?", userID).Desc("updated_unix")
sess := x.Where("owner_id = ?", userID).Desc("uid").Desc("updated_unix")

if setting.UsePostgreSQL {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really dislike this part to check for the used DB

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It has to be done, PostgreSQL uses different syntax.

Copy link
Member

Choose a reason for hiding this comment

The 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

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you like to suggest changes? I replicated what @unknwon did previously.

Copy link
Member

Choose a reason for hiding this comment

The 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 ;)

Copy link
Author

Choose a reason for hiding this comment

The 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.

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")

if setting.UsePostgreSQL {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really dislike this part to check for the used DB

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It has to be done, PostgreSQL uses different syntax.

Copy link
Member

Choose a reason for hiding this comment

The 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

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you like to suggest changes? I replicated what @unknwon did previously.

Copy link
Member

Choose a reason for hiding this comment

The 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 ;)

Copy link
Author

Choose a reason for hiding this comment

The 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.

@@ -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")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

order by uid desc will disable order by updated_unix desc.

Copy link
Author

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?

Copy link
Member

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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

huh?

Copy link
Member

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 ?

Copy link
Member

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!

Copy link
Member

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 :)

Copy link
Member

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 ?

@strk strk modified the milestones: 1.1.0, 1.0.0 Nov 6, 2016
@strk
Copy link
Member

strk commented Nov 8, 2016

LGTM (where's the automatic labels addition by lgtm gone ?)

@lunny
Copy link
Member

lunny commented Nov 8, 2016

@LefsFlarey there are file conflicts.

@DblK DblK added the lgtm/need 1 This PR needs approval from one additional maintainer to be merged. label Nov 8, 2016
@codecov-io
Copy link

codecov-io commented Nov 8, 2016

Current coverage is 3.13% (diff: 0.00%)

Merging #19 into master will decrease coverage by <.01%

@@            master       #19   diff @@
========================================
  Files           33        33          
  Lines         7823      7836    +13   
  Methods          0         0          
  Messages         0         0          
  Branches         0         0          
========================================
  Hits           246       246          
- Misses        7557      7570    +13   
  Partials        20        20          

Powered by Codecov. Last update f6d53ec...0eea5f5

@@ -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")
Copy link
Contributor

@thibaultmeyer thibaultmeyer Nov 13, 2016

Choose a reason for hiding this comment

The 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 :

x.Where("owner_id !=? ", user.ID).
        Desc("uid").
        Desc("updated_unix")

or

x.
        Where("owner_id !=? ", user.ID).
        Desc("uid").
        Desc("updated_unix")

@@ -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")
Copy link
Contributor

@thibaultmeyer thibaultmeyer Nov 13, 2016

Choose a reason for hiding this comment

The 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 :

x.Where("owner_id !=? ", user.ID).
        Desc("uid").
        Desc("updated_unix")

or

x.
        Where("owner_id !=? ", user.ID).
        Desc("uid").
        Desc("updated_unix")

@@ -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")
Copy link
Contributor

@thibaultmeyer thibaultmeyer Nov 13, 2016

Choose a reason for hiding this comment

The 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 :

sess := x.Where("owner_id = ?", userID).
        And("is_mirror = ?", true).
        Desc("uid")

or

sess := x.
        Where("owner_id = ?", userID).
        And("is_mirror = ?", true).
        Desc("uid")

@thibaultmeyer
Copy link
Contributor

They are file conflicts since all raw query has been refactored to use XORM in a previous PR

@ghost ghost closed this Nov 14, 2016
@tboerger
Copy link
Member

@LefsFlarey why have you closed this?

@tboerger tboerger removed the lgtm/need 1 This PR needs approval from one additional maintainer to be merged. label Nov 15, 2016
@ghost ghost deleted the feature/sort-repos-by-star branch November 25, 2016 01:38
@tboerger tboerger added reviewed/invalid and removed type/enhancement An improvement of existing functionality labels Nov 29, 2016
@tboerger tboerger removed this from the 1.1.0 milestone Nov 29, 2016
@ghost ghost restored the feature/sort-repos-by-star branch December 11, 2016 05:39
lunny referenced this pull request in lunny/gitea Feb 7, 2019
@go-gitea go-gitea locked and limited conversation to collaborators Nov 23, 2020
@delvh delvh added issue/not-a-bug The reported issue is the intended behavior or the problem is not inside Gitea and removed reviewed/invalid labels Oct 7, 2023
This pull request was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
issue/not-a-bug The reported issue is the intended behavior or the problem is not inside Gitea
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants