Compare commits

...

2 Commits

Author SHA1 Message Date
Gusted
f51a19c537
Check for zero time instant in TimeStamp.IsZero() (#22171) (#22173)
- Backport of #22171
- Currently, the 'IsZero' function for 'TimeStamp' just checks if the
unix time is zero, which is not the behavior of 'Time.IsZero()', but
Gitea is using this method in accordance with the behavior of
'Time.IsZero()'.
  - Adds a new condition to check for the zero time instant.
- Fixes a bug where non-expiring GPG keys where shown as they expired on
Jan 01, 0001.
  - Related https://codeberg.org/Codeberg/Community/issues/791
2022-12-20 10:07:41 +08:00
Christian Ullrich
068e96fbd2
Do not list active repositories as unadopted (#22034) (#22167)
Backport #22034

This fixes a bug where, when searching unadopted repositories, active
repositories will be listed as well. This is because the size of the
array of repository names to check is larger by one than the
`IterateBufferSize`.

For an `IterateBufferSize` of 50, the original code will pass 51
repository names but set the query to `LIMIT 50`. If all repositories in
the query are active (i.e. not unadopted) one of them will be omitted
from the result. Due to the `ORDER BY` clause it will be the oldest (or
least recently modified) one.

Co-authored-by: Christian Ullrich <christian.ullrich@traditionsa.lu>
2022-12-19 12:48:57 +00:00
2 changed files with 9 additions and 4 deletions

View File

@ -13,8 +13,13 @@ import (
// TimeStamp defines a timestamp // TimeStamp defines a timestamp
type TimeStamp int64 type TimeStamp int64
// mock is NOT concurrency-safe!! var (
var mock time.Time // mock is NOT concurrency-safe!!
mock time.Time
// Used for IsZero, to check if timestamp is the zero time instant.
timeZeroUnix = time.Time{}.Unix()
)
// Set sets the time to a mocked time.Time // Set sets the time to a mocked time.Time
func Set(now time.Time) { func Set(now time.Time) {
@ -103,5 +108,5 @@ func (ts TimeStamp) FormatDate() string {
// IsZero is zero time // IsZero is zero time
func (ts TimeStamp) IsZero() bool { func (ts TimeStamp) IsZero() bool {
return int64(ts) == 0 return int64(ts) == 0 || int64(ts) == timeZeroUnix
} }

View File

@ -340,7 +340,7 @@ func ListUnadoptedRepositories(query string, opts *db.ListOptions) ([]string, in
} }
repoNamesToCheck = append(repoNamesToCheck, name) repoNamesToCheck = append(repoNamesToCheck, name)
if len(repoNamesToCheck) > setting.Database.IterateBufferSize { if len(repoNamesToCheck) >= setting.Database.IterateBufferSize {
if err = checkUnadoptedRepositories(userName, repoNamesToCheck, unadopted); err != nil { if err = checkUnadoptedRepositories(userName, repoNamesToCheck, unadopted); err != nil {
return err return err
} }