1
0
mirror of https://github.com/go-gitea/gitea.git synced 2024-11-04 08:17:24 -05:00
gitea/services/repository
Jason Song 1960ad5c90
Improve cache context (#23330)
Related to: #22294 #23186 #23054

Replace: #23218

Some discussion is in the comments of #23218.

Highlights:
- Add Expiration for cache context. If a cache context has been used for
more than 10s, the cache data will be ignored, and warning logs will be
printed.
- Add `discard` field to `cacheContext`, a `cacheContext` with `discard`
true will drop all cached data and won't store any new one.
- Introduce `WithNoCacheContext`, if one wants to run long-life tasks,
but the parent context is a cache context,
`WithNoCacheContext(perentCtx)` will discard the cache data, so it will
be safe to keep the context for a long time.
- It will be fine to treat an original context as a cache context, like
`GetContextData(context.Backgraud())`, no warning logs will be printed.

Some cases about nesting:

When:
- *A*, *B* or *C* means a cache context.
- ~*A*~, ~*B*~ or ~*C*~ means a discard cache context.
- `ctx` means `context.Backgrand()`
- *A(ctx)* means a cache context with `ctx` as the parent context.
- *B(A(ctx))* means a cache context with `A(ctx)` as the parent context.
- `With` means `WithCacheContext`
- `WithNo` means `WithNoCacheContext`

So:
- `With(ctx)` -> *A(ctx)*
- `With(With(ctx))` -> *A(ctx)*, not *B(A(ctx))*
- `With(With(With(ctx)))` -> *A(ctx)*, not *C(B(A(ctx)))*
- `WithNo(ctx)` -> *ctx*, not *~A~(ctx)*
- `WithNo(With(ctx))` -> *~A~(ctx)*
- `WithNo(WithNo(With(ctx)))` -> *~A~(ctx)*, not *~B~(~A~(ctx))*
- `With(WithNo(With(ctx)))` -> *B(~A~(ctx))*
- `WithNo(With(WithNo(With(ctx))))` -> *~B~(~A~(ctx))*
- `With(WithNo(With(WithNo(With(ctx)))))` -> *C(~B~(~A~(ctx)))*
2023-03-08 11:57:05 -06:00
..
archiver refactor some functions to support ctx as first parameter (#21878) 2022-12-03 10:48:26 +08:00
files Use CleanPath instead of path.Clean (#23371) 2023-03-08 20:17:39 +08:00
adopt_test.go Use context parameter in services/repository (#23186) 2023-02-28 16:17:51 -06:00
adopt.go Use context parameter in services/repository (#23186) 2023-02-28 16:17:51 -06:00
avatar_test.go Use context parameter in services/repository (#23186) 2023-02-28 16:17:51 -06:00
avatar.go Use context parameter in services/repository (#23186) 2023-02-28 16:17:51 -06:00
branch.go Use context parameter in services/repository (#23186) 2023-02-28 16:17:51 -06:00
cache.go Implement FSFE REUSE for golang files (#21840) 2022-11-27 18:20:29 +00:00
check.go Refactor git command package to improve security and maintainability (#22678) 2023-02-04 10:30:43 +08:00
fork_test.go Add option to prohibit fork if user reached maximum limit of repositories (#21848) 2022-12-27 15:21:14 -06:00
fork.go Use context parameter in services/repository (#23186) 2023-02-28 16:17:51 -06:00
hooks.go Implement FSFE REUSE for golang files (#21840) 2022-11-27 18:20:29 +00:00
lfs.go Add cron method to gc LFS MetaObjects (#22385) 2023-01-16 13:50:53 -06:00
main_test.go Implement FSFE REUSE for golang files (#21840) 2022-11-27 18:20:29 +00:00
push.go Improve cache context (#23330) 2023-03-08 11:57:05 -06:00
repository_test.go refactor some functions to support ctx as first parameter (#21878) 2022-12-03 10:48:26 +08:00
repository.go Use context parameter in services/repository (#23186) 2023-02-28 16:17:51 -06:00
review_test.go Use context parameter in services/repository (#23186) 2023-02-28 16:17:51 -06:00
review.go Use context parameter in services/repository (#23186) 2023-02-28 16:17:51 -06:00
template.go Use context parameter in services/repository (#23186) 2023-02-28 16:17:51 -06:00
transfer_test.go Rename almost all Ctx functions (#22071) 2022-12-10 10:46:31 +08:00
transfer.go Use context parameter in services/repository (#23186) 2023-02-28 16:17:51 -06:00