refactor(handlers): replace temporary variable pointer pattern with new() builtin

Simplify pointer creation across kobo, koreader, and queue handlers by
replacing the two-step pattern (assign to local, then take address) with
inline new() calls. This reduces verbosity without changing behavior:

Before:
  remaining := int(a - b)
  pagesRemaining = &remaining

After:
  pagesRemaining = new(int(a - b))

Covers page calculations, chapter/progress fields, UUID formatting,
and timestamp string conversions.
This commit is contained in:
2026-04-20 08:57:42 -04:00
parent 45df899889
commit 8ac6e1ac79
3 changed files with 9 additions and 18 deletions
+1 -2
View File
@@ -303,8 +303,7 @@ func (h *KoboHandler) Initialization(c *echo.Context) error {
lastModified = progress.LastReadAt.Time.Format(time.RFC3339) lastModified = progress.LastReadAt.Time.Format(time.RFC3339)
} }
if progress.TotalPages.Valid && progress.CurrentPage.Valid { if progress.TotalPages.Valid && progress.CurrentPage.Valid {
remaining := int(progress.TotalPages.Int32 - progress.CurrentPage.Int32) pagesRemaining = new(int(progress.TotalPages.Int32 - progress.CurrentPage.Int32))
pagesRemaining = &remaining
} }
} }
+6 -12
View File
@@ -601,24 +601,19 @@ func (h *KOReaderHandler) GetMetadata(c *echo.Context) error {
progressData.Epubcfi = &progress.Epubcfi.String progressData.Epubcfi = &progress.Epubcfi.String
} }
if progress.Chapter.Valid { if progress.Chapter.Valid {
ch := int(progress.Chapter.Int32) progressData.Chapter = new(int(progress.Chapter.Int32))
progressData.Chapter = &ch
} }
if progress.ChapterProgress.Valid { if progress.ChapterProgress.Valid {
cp := progress.ChapterProgress.Float64 progressData.ChapterProgress = new(progress.ChapterProgress.Float64)
progressData.ChapterProgress = &cp
} }
if progress.CharacterOffset.Valid { if progress.CharacterOffset.Valid {
co := int64(progress.CharacterOffset.Int64) progressData.Character = new(int64(progress.CharacterOffset.Int64))
progressData.Character = &co
} }
if progress.CurrentPage.Valid { if progress.CurrentPage.Valid {
cp := int(progress.CurrentPage.Int32) progressData.Page = new(int(progress.CurrentPage.Int32))
progressData.Page = &cp
} }
if progress.TotalPages.Valid { if progress.TotalPages.Valid {
tp := int(progress.TotalPages.Int32) progressData.TotalPages = new(int(progress.TotalPages.Int32))
progressData.TotalPages = &tp
} }
annotations, err := h.db.GetAnnotationsForBook(c.Request().Context(), database.GetAnnotationsForBookParams{ annotations, err := h.db.GetAnnotationsForBook(c.Request().Context(), database.GetAnnotationsForBookParams{
@@ -698,8 +693,7 @@ func (h *KOReaderHandler) GetLibrary(c *echo.Context) error {
if err == nil { if err == nil {
percentRead = progress.Percentage.Float64 percentRead = progress.Percentage.Float64
if progress.TotalPages.Valid && progress.CurrentPage.Valid { if progress.TotalPages.Valid && progress.CurrentPage.Valid {
remaining := int(progress.TotalPages.Int32 - progress.CurrentPage.Int32) pagesRemaining = new(int(progress.TotalPages.Int32 - progress.CurrentPage.Int32))
pagesRemaining = &remaining
} }
if progress.LastReadAt.Valid { if progress.LastReadAt.Valid {
lastModified = progress.LastReadAt.Time.Format(time.RFC3339) lastModified = progress.LastReadAt.Time.Format(time.RFC3339)
+2 -4
View File
@@ -310,8 +310,7 @@ func uuidPtrToString(u pgtype.UUID) *string {
if !u.Valid { if !u.Valid {
return nil return nil
} }
s := uuid.UUID(u.Bytes).String() return new(uuid.UUID(u.Bytes).String())
return &s
} }
func textPtrToString(t pgtype.Text) *string { func textPtrToString(t pgtype.Text) *string {
@@ -325,6 +324,5 @@ func timestamptzPtrToString(t pgtype.Timestamptz) *string {
if !t.Valid { if !t.Valid {
return nil return nil
} }
s := t.Time.Format("2006-01-02T15:04:05Z07:00") return new(t.Time.Format("2006-01-02T15:04:05Z07:00"))
return &s
} }