diff --git a/internal/app/server/app.go b/internal/app/server/app.go index 821744f..c06f794 100644 --- a/internal/app/server/app.go +++ b/internal/app/server/app.go @@ -19,6 +19,7 @@ import ( "github.com/AFASystems/presence/internal/pkg/model" "github.com/AFASystems/presence/internal/pkg/service" "gorm.io/gorm" + "gorm.io/gorm/clause" ) // ServerApp holds dependencies and state for the server service. @@ -87,7 +88,7 @@ func (a *ServerApp) Init(ctx context.Context) error { } for _, c := range configs { - a.DB.Create(&c) + a.DB.Clauses(clause.OnConflict{DoNothing: true}).Create(&c) } a.DB.Find(&configs) for _, c := range configs { diff --git a/internal/pkg/service/beacon_service.go b/internal/pkg/service/beacon_service.go index a9b2496..14e25f3 100644 --- a/internal/pkg/service/beacon_service.go +++ b/internal/pkg/service/beacon_service.go @@ -151,9 +151,9 @@ func LocationToBeaconServiceAI(msg model.HTTPLocation, db *gorm.DB, writer *kafk func SendAlert(trackerId, alertType string, writer *kafka.Writer, ctx context.Context, db *gorm.DB) { var existingAlert model.Alert - result := db.Select("status").Where("tracker_id = ? AND type = ?", trackerId, alertType).Order("timestamp DESC").First(&existingAlert) + result := db.Select("status").Where("tracker_id = ? AND type = ?", trackerId, alertType).Order("timestamp DESC").Limit(1).Find(&existingAlert) - if result.Error == gorm.ErrRecordNotFound || existingAlert.Status == "resolved" { + if result.RowsAffected == 0 || existingAlert.Status == "resolved" { alert := model.Alert{ ID: uuid.New().String(), TrackerID: trackerId, diff --git a/location b/location index 663e229..87cc534 100755 Binary files a/location and b/location differ diff --git a/scripts/config/settings.sh b/scripts/config/settings.sh index d086e75..50c8505 100755 --- a/scripts/config/settings.sh +++ b/scripts/config/settings.sh @@ -7,7 +7,7 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" curl -s -X PATCH "${BASE_URL}/reslevis/settings" \ -H "Content-Type: application/json" \ -d '{ - "current_algorithm": "filter", + "current_algorithm": "ai", "last_seen_threshold": 310, "beacon_metric_size": 100, "HA_send_interval": 60, diff --git a/server b/server index 506c280..f1190b4 100755 Binary files a/server and b/server differ