mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-12-07 22:19:48 +00:00
Within Codeberg we are looking into distributing the database queries, we tried forgejo/forgejo!7212 on several occasions but never got it to work. After a long debugging session in a staging environment I was able to find two bugs that made it impossible for this feature to work: forgejo/docs!1587 which resulted in replica engines never being configured and used if you followed the documentation. The other bug is what this patch intends to fix. In order to do some database operation, you need the database engine - it will first look if one is set for the context (only useful for transactions) and otherwise create a new session of the engine from the master engine `x`. The problem is that `x` is explicitly set to be the master engine and not the engine group (that includes the replica engines) - Unless the code uses `DefaultContext`, which is almost nowhere used after some great refactoring in Gitea to use the passed context, it did not use the replica engines. Get engine from the `DefaultContext` (which is set to the enginegroup) and create a new session from that. |
||
|---|---|---|
| .. | ||
| install | ||
| paginator | ||
| collation.go | ||
| common.go | ||
| consistency.go | ||
| context.go | ||
| context_committer_test.go | ||
| context_test.go | ||
| convert.go | ||
| engine.go | ||
| engine_test.go | ||
| error.go | ||
| foreign_keys.go | ||
| index.go | ||
| index_test.go | ||
| iterate.go | ||
| iterate_test.go | ||
| list.go | ||
| list_test.go | ||
| log.go | ||
| main_test.go | ||
| name.go | ||
| search.go | ||
| sequence.go | ||
| sql_postgres_with_schema.go | ||
| table_names_test.go | ||