Skip to content

Commit

Permalink
feat: add record count limit in database
Browse files Browse the repository at this point in the history
  • Loading branch information
Diegiwg committed Jun 26, 2024
1 parent 5995304 commit 189aa1c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions data/data.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package data

const DATA_BASE_RECORDS_LIMIT = 1_000
4 changes: 4 additions & 0 deletions data/save.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ func SaveRecordToFile(ctx *cli.Context, table *model.RecordTable) {

dbPath := filepath.Join(USER_HOME, "tt.db")

if len(table.Records) > DATA_BASE_RECORDS_LIMIT {
table.Records = table.Records[len(table.Records)-DATA_BASE_RECORDS_LIMIT:]
}

data, err := json.Marshal(table)
if err != nil {
panic(err)
Expand Down

0 comments on commit 189aa1c

Please sign in to comment.