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

Use db.Find instead of writing methods for every object #28084

Merged
merged 32 commits into from Nov 24, 2023

Conversation

lunny
Copy link
Member

@lunny lunny commented Nov 16, 2023

For those simple objects, it's unnecessary to write the find and count methods again and again.

@lunny lunny added the type/refactoring Existing code has been cleaned up. There should be no new functionality. label Nov 16, 2023
@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Nov 16, 2023
@pull-request-size pull-request-size bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Nov 16, 2023
@github-actions github-actions bot added the modifies/api This PR adds API routes or modifies them label Nov 16, 2023
@lunny lunny changed the title WIP: Use db.Find instead of writing methods for every object Use db.Find instead of writing methods for every object Nov 16, 2023
@pull-request-size pull-request-size bot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Nov 17, 2023
@github-actions github-actions bot added the modifies/cli PR changes something on the CLI, i.e. gitea doctor or gitea admin label Nov 17, 2023
routers/web/shared/actions/runners.go Outdated Show resolved Hide resolved
routers/api/v1/org/org.go Outdated Show resolved Hide resolved
routers/api/v1/notify/user.go Outdated Show resolved Hide resolved
models/auth/source.go Outdated Show resolved Hide resolved
routers/web/user/notification.go Show resolved Hide resolved
models/activities/notification_list.go Outdated Show resolved Hide resolved
models/activities/notification_list.go Outdated Show resolved Hide resolved
models/activities/notification_list.go Outdated Show resolved Hide resolved
models/activities/notification_list.go Outdated Show resolved Hide resolved
models/db/context.go Outdated Show resolved Hide resolved
@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Nov 18, 2023
@wxiaoguang
Copy link
Contributor

Why sometimes db.Find[T] but sometimes db.Find[*T]? Could there be a consistent behavior which only accepts db.Find[T] and returns *T[]?

@lunny
Copy link
Member Author

lunny commented Nov 23, 2023

Why sometimes db.Find[T] but sometimes db.Find[*T]? Could there be a consistent behavior which only accepts db.Find[T] and returns *T[]?

All db.Find and db.FindAndCount has been using pointer to struct but for db.Count, if we use a pointer, we need introduce reflect so I don't think it's necessary. So all db.Count should use struct directly.

@wxiaoguang
Copy link
Contributor

How to avoid low-level mistakes? When reviewing PRs, which is right while which is wrong?

  • db.Find[T]
  • db.Find[*T]
  • db.Count[T]
  • db.Count[*T]

I do not think leaving low-level mistakes in a framework is healthy to a big project.

@lunny
Copy link
Member Author

lunny commented Nov 23, 2023

How to avoid low-level mistakes? When reviewing PRs, which is right while which is wrong?

* db.Find[T]

* db.Find[*T]

* db.Count[T]

* db.Count[*T]

I do not think leaving low-level mistakes in a framework is healthy to a big project.

[x] db.Find[T]
[x] db.Find[*T]
[x] db.Count[T]
x db.Count[*T]

Let me try to avoid db.Count[*T].

@wxiaoguang
Copy link
Contributor

[x] db.Find[T]
[x] db.Find[*T]
[x] db.Count[T]

Why not just use db.Find[T](...) *T[] and db.Count[T](...)?

@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Nov 24, 2023
@lunny lunny added the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Nov 24, 2023
@lunny lunny enabled auto-merge (squash) November 24, 2023 03:26
@GiteaBot
Copy link
Contributor

@lunny please fix the merge conflicts. 🍵

@GiteaBot GiteaBot removed the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Nov 24, 2023
@lunny lunny added the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Nov 24, 2023
@lunny lunny merged commit df1e7d0 into go-gitea:main Nov 24, 2023
25 checks passed
@GiteaBot GiteaBot removed the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Nov 24, 2023
zjjhot added a commit to zjjhot/gitea that referenced this pull request Nov 24, 2023
* giteaofficial/main:
  Use db.Find instead of writing methods for every object (go-gitea#28084)
  Edit Discord Badge (go-gitea#28188)
  Use restricted sanitizer for repository description (go-gitea#28141)
  Use full width for PR comparison (go-gitea#28182)
  Make CORS work for oauth2 handlers (go-gitea#28184)
  Fix missing buttons (go-gitea#28179)
pangliang added a commit to pangliang/gitea that referenced this pull request Nov 29, 2023
pangliang added a commit to pangliang/gitea that referenced this pull request Dec 5, 2023
fuxiaohei pushed a commit to fuxiaohei/gitea that referenced this pull request Jan 17, 2024
For those simple objects, it's unnecessary to write the find and count
methods again and again.
@lunny lunny deleted the lunny/use_db_find branch January 27, 2024 09:06
silverwind pushed a commit to silverwind/gitea that referenced this pull request Feb 20, 2024
For those simple objects, it's unnecessary to write the find and count
methods again and again.
@go-gitea go-gitea locked as resolved and limited conversation to collaborators Feb 22, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. modifies/api This PR adds API routes or modifies them modifies/cli PR changes something on the CLI, i.e. gitea doctor or gitea admin size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. type/refactoring Existing code has been cleaned up. There should be no new functionality.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants