Skip to content

Commit c26349b

Browse files
authored
Optimize GRPC duration (#616)
* no need to validate current block height * set index into some tables for speed up latency get a lot of records * remove unused a line of codes
1 parent da6f66e commit c26349b

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

common/database/migration.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,15 @@ func (m *Migration) Init() error {
304304
PRIMARY KEY("multisig_address", "block_height")
305305
)
306306
`,
307+
`
308+
CREATE INDEX "node_registry_height_idx" ON "node_registry" ("height")
309+
`,
310+
`
311+
CREATE INDEX "skipped_blocksmith_block_height_idx" ON "skipped_blocksmith" ("block_height")
312+
`,
313+
`
314+
CREATE INDEX "published_receipt_block_height_idx" ON "published_receipt" ("block_height")
315+
`,
307316
}
308317
return nil
309318
}
@@ -341,12 +350,14 @@ func (m *Migration) Apply() error {
341350
return err
342351
}
343352
if m.CurrentVersion != nil {
353+
*m.CurrentVersion++
344354
err = m.Query.ExecuteTransaction(`UPDATE "migration"
345-
SET "version" = ?, "created_date" = datetime('now');`, *m.CurrentVersion+1)
355+
SET "version" = ?, "created_date" = datetime('now');`, m.CurrentVersion)
346356
if err != nil {
347357
return err
348358
}
349359
} else {
360+
m.CurrentVersion = &version // should 0 value not nil anymore
350361
err = m.Query.ExecuteTransaction(`
351362
INSERT INTO "migration" (
352363
"version",
@@ -362,7 +373,6 @@ func (m *Migration) Apply() error {
362373
}
363374
}
364375

365-
m.CurrentVersion = &version
366376
err = m.Query.CommitTx()
367377
if err != nil {
368378
return err

0 commit comments

Comments
 (0)