Skip to content

Commit

Permalink
fix: query sign record by id directly
Browse files Browse the repository at this point in the history
  • Loading branch information
LinZexiao committed Feb 28, 2023
1 parent c7af9ea commit 02b8d13
Showing 1 changed file with 1 addition and 15 deletions.
16 changes: 1 addition & 15 deletions storage/sqlite/sign_record.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,6 @@ func (s *sqliteSignRecord) toSignRecord() *storage.SignRecord {
return ret
}

func parseId(id string) (signer string, createAt time.Time, err error) {
var nanoSec int64
_, err = fmt.Sscanf(id, "%d-%s", &nanoSec, &signer)
if err != nil {
return signer, createAt, fmt.Errorf("parse id: %w", err)
}
createAt = time.Unix(0, nanoSec)
return signer, createAt, err
}

type SqliteRecorder struct {
db *gorm.DB
}
Expand Down Expand Up @@ -104,11 +94,7 @@ func (s *SqliteRecorder) QueryRecord(params *storage.QueryParams) ([]storage.Sig
query := s.db

if params.ID != "" {
signer, createAt, err := parseId(params.ID)
if err != nil {
return nil, fmt.Errorf("parse id: %w", err)
}
query = query.Where("signer = ?", signer).Where("created_at <= ?", createAt).Where("created_at >= ?", createAt)
query = query.Where("id = ?", params.ID)
} else {
if params.Signer != address.Undef {
query = query.Where("signer = ?", params.Signer.String())
Expand Down

0 comments on commit 02b8d13

Please sign in to comment.