check tcp when insert telegram to db
This commit is contained in:
+21
-19
@@ -66,26 +66,28 @@ func InitDb(file string, init bool) error {
|
||||
}
|
||||
|
||||
func InsertTelegram(teleString string) {
|
||||
getWriteLock()
|
||||
db := getDb()
|
||||
defer db.Close()
|
||||
var insertSQL string
|
||||
if ClientReady && WriteToClient(teleString) == nil {
|
||||
insertSQL = InsertOld
|
||||
} else {
|
||||
insertSQL = InsertNew
|
||||
}
|
||||
stmt, _ := db.Prepare(insertSQL)
|
||||
if Tcp {
|
||||
getWriteLock()
|
||||
db := getDb()
|
||||
defer db.Close()
|
||||
var insertSQL string
|
||||
if ClientReady && WriteToClient(teleString) == nil {
|
||||
insertSQL = InsertOld
|
||||
} else {
|
||||
insertSQL = InsertNew
|
||||
}
|
||||
stmt, _ := db.Prepare(insertSQL)
|
||||
|
||||
defer stmt.Close()
|
||||
result, err := stmt.Exec(teleString)
|
||||
id, _ := result.LastInsertId()
|
||||
checkDbErr(err, "error in insert telegram ")
|
||||
isWriting = false
|
||||
if insertSQL == InsertOld {
|
||||
Log.Info("telegram processed ", zap.Int64("id", id))
|
||||
} else {
|
||||
Log.Info("telegram saved ", zap.Int64("id", id))
|
||||
defer stmt.Close()
|
||||
result, err := stmt.Exec(teleString)
|
||||
id, _ := result.LastInsertId()
|
||||
checkDbErr(err, "error in insert telegram ")
|
||||
isWriting = false
|
||||
if insertSQL == InsertOld {
|
||||
Log.Info("telegram processed ", zap.Int64("id", id))
|
||||
} else {
|
||||
Log.Info("telegram saved ", zap.Int64("id", id))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user