File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -140,20 +140,11 @@ impl Store {
140140 for ( & height, hash) in & local_chain. blocks {
141141 match hash {
142142 Some ( hash) => {
143- // Avoid inserting new rows of existing height.
144- // FIXME: The correct way to handle this is to have a unique constraint on `height`
145- // in the block table schema.
146- let row_option = sqlx:: query ( "SELECT height FROM block WHERE height = $1" )
143+ sqlx:: query ( "INSERT OR IGNORE INTO block(height, hash) VALUES($1, $2)" )
147144 . bind ( height)
148- . fetch_optional ( & self . pool )
145+ . bind ( hash. to_string ( ) )
146+ . execute ( & self . pool )
149147 . await ?;
150- if row_option. is_none ( ) {
151- sqlx:: query ( "INSERT OR IGNORE INTO block(height, hash) VALUES($1, $2)" )
152- . bind ( height)
153- . bind ( hash. to_string ( ) )
154- . execute ( & self . pool )
155- . await ?;
156- }
157148 }
158149 None => {
159150 sqlx:: query ( "DELETE FROM block WHERE height = $1" )
You can’t perform that action at this time.
0 commit comments