docs: util function docstrings

This commit is contained in:
ae 2025-05-04 11:24:00 +03:00
parent 2b9b14210c
commit 8535d011d0
Signed by: ae
GPG Key ID: 995EFD5C1B532B3E

View File

@ -206,6 +206,9 @@ func sha1ContentHash(title, content string) string {
return hashStr return hashStr
} }
// Parse either an absolute (e.g. '2006-01-02') or a relative expiration date (e.g. '+3d') from
// the beginning of the title prefixed with either '@exp:' or '@expires:'. The actual note
// expiration will be set to the end of that particular date (+0000 UTC).
func parseTitleExpiration(title *string) (*time.Time, error) { func parseTitleExpiration(title *string) (*time.Time, error) {
// Absolute date format: '@exp:YYYY-MM-DD' (or '@expires:') // Absolute date format: '@exp:YYYY-MM-DD' (or '@expires:')
if match := dateFormatRegex.FindStringSubmatch(*title); match != nil { if match := dateFormatRegex.FindStringSubmatch(*title); match != nil {
@ -265,6 +268,7 @@ func parseTitleExpiration(title *string) (*time.Time, error) {
return nil, ErrNoExpirationDateFound return nil, ErrNoExpirationDateFound
} }
// Ensure a given date (time) is between the current time and current time + `maxFutureExpirationYears`.
func validateExpirationDate(date time.Time) error { func validateExpirationDate(date time.Time) error {
now := time.Now() now := time.Now()
@ -280,6 +284,8 @@ func validateExpirationDate(date time.Time) error {
return nil return nil
} }
// Run a database cleanup task that queries the currently expired notes in the database, prints
// metadata about them, and deletes them.
func cleanupNotes(ctx context.Context, q *data.Queries) { func cleanupNotes(ctx context.Context, q *data.Queries) {
expiredNotes, err := q.ListExpiredNotes(ctx) expiredNotes, err := q.ListExpiredNotes(ctx)
if err != nil { if err != nil {
@ -305,6 +311,7 @@ func cleanupNotes(ctx context.Context, q *data.Queries) {
log.Info().Msgf("Successfully deleted %d expired notes during scheduled cleanup", len(expiredNotes)) log.Info().Msgf("Successfully deleted %d expired notes during scheduled cleanup", len(expiredNotes))
} }
// Run a database cleanup task that deletes the expired and revoked refresh tokens.
func cleanupRefreshTokens(ctx context.Context, q *data.Queries) { func cleanupRefreshTokens(ctx context.Context, q *data.Queries) {
rowsAffected, err := q.DeleteExpiredRefreshTokens(ctx) rowsAffected, err := q.DeleteExpiredRefreshTokens(ctx)
if err != nil { if err != nil {