Skip to content

Commit

Permalink
minor: add elapsed time log
Browse files Browse the repository at this point in the history
  • Loading branch information
j178 committed Dec 18, 2023
1 parent 45076f8 commit 72540da
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
8 changes: 6 additions & 2 deletions leetcode/cache_json.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ func (c *jsonCache) doLoad() error {
func (c *jsonCache) load() {
c.once.Do(
func() {
defer func(now time.Time) {
log.Debug("cache loaded", "path", c.path, "elapsed", time.Since(now))
defer func(start time.Time) {
log.Debug("cache loaded", "path", c.path, "elapsed", time.Since(start))
}(time.Now())
err := c.doLoad()
if err != nil {
Expand Down Expand Up @@ -114,6 +114,10 @@ func (c *jsonCache) GetBySlug(slug string) *QuestionData {
}

func (c *jsonCache) GetById(id string) *QuestionData {
defer func(start time.Time) {
log.Debug("get by id", "elapsed", time.Since(start))
}(time.Now())

c.load()
return c.frontIds[id]
}
Expand Down
10 changes: 8 additions & 2 deletions leetcode/cache_sqlite.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build !json

package leetcode

import (
Expand Down Expand Up @@ -70,8 +72,8 @@ func (c *sqliteCache) CacheFile() string {
func (c *sqliteCache) load() {
c.once.Do(
func() {
defer func(now time.Time) {
log.Debug("cache loaded", "path", c.path, "time", time.Since(now))
defer func(start time.Time) {
log.Debug("cache loaded", "path", c.path, "elapsed", time.Since(start))
}(time.Now())
var err error
c.db, err = sqlite.OpenConn(c.path)
Expand Down Expand Up @@ -248,6 +250,10 @@ func (c *sqliteCache) GetBySlug(slug string) *QuestionData {
}

func (c *sqliteCache) GetById(id string) *QuestionData {
defer func(start time.Time) {
log.Debug("get by id", "elapsed", time.Since(start))
}(time.Now())

c.load()
if c.db == nil {
return nil
Expand Down

0 comments on commit 72540da

Please sign in to comment.