aboutsummaryrefslogtreecommitdiffstats
path: root/models/db/context.go
Commit message (Collapse)AuthorAgeFilesLines
* Refactor deletion (#28610)delvh2023-12-251-7/+27
| | | | | | | | | | | | | | | | | | Introduce the new generic deletion methods - `func DeleteByID[T any](ctx context.Context, id int64) (int64, error)` - `func DeleteByIDs[T any](ctx context.Context, ids ...int64) error` - `func Delete[T any](ctx context.Context, opts FindOptions) (int64, error)` So, we no longer need any specific deletion method and can just use the generic ones instead. Replacement of #28450 Closes #28450 --------- Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
* Remove GetByBean method because sometimes it's danger when query condition ↵Lunny Xiao2023-12-071-8/+38
| | | | | | | | | | | | | | | | | | | | parameter is zero and also introduce new generic methods (#28220) The function `GetByBean` has an obvious defect that when the fields are empty values, it will be ignored. Then users will get a wrong result which is possibly used to make a security problem. To avoid the possibility, this PR removed function `GetByBean` and all references. And some new generic functions have been introduced to be used. The recommand usage like below. ```go // if query an object according id obj, err := db.GetByID[Object](ctx, id) // query with other conditions obj, err := db.Get[Object](ctx, builder.Eq{"a": a, "b":b}) ```
* Use db.Find instead of writing methods for every object (#28084)Lunny Xiao2023-11-241-0/+5
| | | | For those simple objects, it's unnecessary to write the find and count methods again and again.
* Improve DeleteByID (#26904)Lunny Xiao2023-09-051-1/+1
|
* Replace `interface{}` with `any` (#25686)silverwind2023-07-041-11/+11
| | | | | Result of running `perl -p -i -e 's#interface\{\}#any#g' **/*` and `make fmt`. Basically the same [as golang did](https://github.com/golang/go/commit/2580d0e08d5e9f979b943758d3c49877fb2324cb).
* Use a separate admin page to show global stats, remove `actions` stat (#25062)wxiaoguang2023-06-031-25/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Before, Gitea shows the database table stats on the `admin dashboard` page. It has some problems: * `count(*)` is quite heavy. If tables have many records, this blocks loading the admin page blocks for a long time * Some users had even reported issues that they can't visit their admin page because this page causes blocking or `50x error (reverse proxy timeout)` * The `actions` stat is not useful. The table is simply too large. Does it really matter if it contains 1,000,000 rows or 9,999,999 rows? * The translation `admin.dashboard.statistic_info` is difficult to maintain. So, this PR uses a separate page to show the stats and removes the `actions` stat. ![image](https://github.com/go-gitea/gitea/assets/2114189/babf7c61-b93b-4a62-bfaa-22983636427e) ## :warning: BREAKING The `actions` Prometheus metrics collector has been removed for the reasons mentioned beforehand. Please do not rely on its output anymore.
* Remove all package data after tests (#22984)KN4CK3R2023-02-231-1/+12
| | | | | | | | Fixes #21020 --------- Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: zeripath <art27@cantab.net>
* Move delete user to service (#22478)Lunny Xiao2023-02-131-0/+26
| | | | | | Move delete user to service Co-authored-by: delvh <dev.lh@web.de> Co-authored-by: Jason Song <i@wolfogre.com>
* Fix halfCommitter and WithTx (#22366)Jason Song2023-01-091-5/+22
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Related to #22362. I overlooked that there's always `committer.Close()`, like: ```go ctx, committer, err := db.TxContext(db.DefaultContext) if err != nil { return nil } defer committer.Close() // ... if err != nil { return nil } // ... return committer.Commit() ``` So the `Close` of `halfCommitter` should ignore `commit and close`, it's not a rollback. See: [Why `halfCommitter` and `WithTx` should rollback IMMEDIATELY or commit LATER](https://github.com/go-gitea/gitea/pull/22366#issuecomment-1374778612). Co-authored-by: techknowlogick <techknowlogick@gitea.io>
* Always reuse transaction (#22362)Jason Song2023-01-081-30/+41
|
* Support estimated count with multiple schemas (#22276)Jason Song2022-12-301-1/+4
| | | | The `EstimateCount` could be incorrect when the table lives in multiple schemas. Related to #19775.
* Update go dev dependencies (#22064)silverwind2022-12-081-2/+4
| | | | | `golangci-lint` [deprecated](https://github.com/golangci/golangci-lint/issues/1841) a bunch of linters, removed them.
* Implement FSFE REUSE for golang files (#21840)flynnnnnnnnnn2022-11-271-2/+1
| | | | | | | | | Change all license headers to comply with REUSE specification. Fix #16132 Co-authored-by: flynnnnnnnnnn <flynnnnnnnnnn@github> Co-authored-by: John Olheiser <john.olheiser@gmail.com>
* Allow detect whether it's in a database transaction for a context.Context ↵Lunny Xiao2022-11-121-7/+47
| | | | | | | | | | | | | | | | (#21756) Fix #19513 This PR introduce a new db method `InTransaction(context.Context)`, and also builtin check on `db.TxContext` and `db.WithTx`. There is also a new method `db.AutoTx` has been introduced but could be used by other PRs. `WithTx` will always open a new transaction, if a transaction exist in context, return an error. `AutoTx` will try to open a new transaction if no transaction exist in context. That means it will always enter a transaction if there is no error. Co-authored-by: delvh <dev.lh@web.de> Co-authored-by: 6543 <6543@obermui.de>
* Merge db.Iterate and IterateObjects (#21641)Lunny Xiao2022-10-311-10/+0
| | | These two functions are similiar, merge them.
* Fix various typos (#20338)luzpaz2022-07-121-1/+1
| | | | | | | * Fix various typos Found via `codespell -q 3 -S ./options/locale,./options/license,./public/vendor -L actived,allways,attachements,ba,befores,commiter,pullrequest,pullrequests,readby,splitted,te,unknwon` Co-authored-by: zeripath <art27@cantab.net>
* Adjust transaction handling via db.Context (#20031)Lunny Xiao2022-06-201-26/+19
|
* Move tests as seperate sub packages to reduce duplicated file names (#19951)Lunny Xiao2022-06-151-1/+1
|
* Estimate Action Count in Statistics (#19775)zeripath2022-05-211-0/+22
|
* Use for a repo action one database transaction (#19576)65432022-05-031-2/+9
| | | | | ... more context (part of #9307)
* Move deletebeans into models/db (#18781)Lunny Xiao2022-02-171-0/+11
|
* Propagate context and ensure git commands run in request context (#17868)zeripath2022-01-191-1/+6
| | | | | | | | | This PR continues the work in #17125 by progressively ensuring that git commands run within the request context. This now means that the if there is a git repo already open in the context it will be used instead of reopening it. Signed-off-by: Andrew Thornton <art27@cantab.net>
* Remove NewSession method from db.Engine interface (#17577)Lunny Xiao2021-11-211-29/+26
| | | | | | | | | | | | | * Remove NewSession method from db.Engine interface * Fix bug * Some improvements * Fix bug * Fix test * Use XXXBean instead of XXXExample
* Ensure that git daemon export ok is created for mirrors (#17243)zeripath2021-10-131-0/+8
| | | | | | | | | | | | | * Ensure that git daemon export ok is created for mirrors There is an issue with #16508 where it appears that create repo requires that the repo does not exist. This causes #17241 where an error is reported because of this. This PR fixes this and also runs update-server-info for mirrors and generated repos. Fix #17241 Signed-off-by: Andrew Thornton <art27@cantab.net>
* DBContext is just a Context (#17100)zeripath2021-09-231-11/+74
| | | | | | | | | | | | | | | | | | | | | | | | | * DBContext is just a Context This PR removes some of the specialness from the DBContext and makes it context This allows us to simplify the GetEngine code to wrap around any context in future and means that we can change our loadRepo(e Engine) functions to simply take contexts. Signed-off-by: Andrew Thornton <art27@cantab.net> * fix unit tests Signed-off-by: Andrew Thornton <art27@cantab.net> * another place that needs to set the initial context Signed-off-by: Andrew Thornton <art27@cantab.net> * avoid race Signed-off-by: Andrew Thornton <art27@cantab.net> * change attachment error Signed-off-by: Andrew Thornton <art27@cantab.net>
* Move db related basic functions to models/db (#17075)Lunny Xiao2021-09-191-0/+86
* Move db related basic functions to models/db * Fix lint * Fix lint * Fix test * Fix lint * Fix lint * revert unnecessary change * Fix test * Fix wrong replace string * Use *Context * Correct committer spelling and fix wrong replaced words Co-authored-by: zeripath <art27@cantab.net>