Skip to content

Commit

Permalink
fix db queries
Browse files Browse the repository at this point in the history
  • Loading branch information
inciner8r committed Apr 14, 2024
1 parent 18ea31c commit 64588a4
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions app/p2p-Node/p2p-node.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,16 @@ func Init() {
threshold := 6 * time.Hour
if duration > threshold {
fmt.Println("The node is inactive for too long, deleting ", node.Id)
if err := db.Model(&models.Node{}).Delete(node).Error; err != nil {
logrus.Error("failed to delete node: ", err.Error())
if err := db.Where("id = ?", node.Id).Delete(&models.Node{}).Error; err != nil {
logrus.Error("failed to delete nodes: ", err.Error())
continue
}
}
} else {
fmt.Printf("Connected to peer %s\n", peerInfo.ID.String())
node.Status = "active"
node.LastPingedTimeStamp = time.Now().Unix()
if err := db.Model(&models.Node{}).Save(&node).Error; err != nil {
if err := db.Model(&models.Node{}).Where("id = ?", node.Id).Save(&node).Error; err != nil {
logrus.Error("failed to update node: ", err.Error())
continue
}
Expand Down

0 comments on commit 64588a4

Please sign in to comment.