lint: remove unused sync/signin, sync/sms, platform/trap, platform/arcgis code
- Delete sync/signin.go (entirely unused, no routes registered) - Delete sync/sms.go (entirely unused, no routes registered) - Remove toTemplateTrapData and fsToTime from platform/trap.go - Remove 8 orphaned helper functions from platform/arcgis.go
This commit is contained in:
parent
fa012bebca
commit
40ffc2a3ba
4 changed files with 0 additions and 597 deletions
|
|
@ -33,7 +33,6 @@ import (
|
|||
"github.com/aarondl/opt/omit"
|
||||
"github.com/aarondl/opt/omitnull"
|
||||
"github.com/alitto/pond/v2"
|
||||
"github.com/jackc/pgx/v5"
|
||||
"github.com/rs/zerolog"
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/twpayne/go-geom"
|
||||
|
|
@ -674,236 +673,6 @@ func saveRawQuery(fssync fieldseeker.FieldSeeker, layer arcgis.LayerFeature, que
|
|||
}
|
||||
*/
|
||||
|
||||
func insertRowFromFeature(ctx context.Context, table string, sorted_columns []string, feature *response.Feature, org_id int32) error {
|
||||
txn, err := db.PGInstance.BobDB.BeginTx(ctx, nil)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Unable to start transaction")
|
||||
}
|
||||
defer lint.LogOnErrRollback(txn.Rollback, ctx, "rollback")
|
||||
|
||||
err = insertRowFromFeatureFS(ctx, txn, table, sorted_columns, feature, org_id)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Unable to insert FS: %w", err)
|
||||
}
|
||||
|
||||
err = insertRowFromFeatureHistory(ctx, txn, table, sorted_columns, feature, org_id, 1)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Failed to insert history: %w", err)
|
||||
}
|
||||
|
||||
if err := txn.Commit(ctx); err != nil {
|
||||
return fmt.Errorf("Failed to commit transaction: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func insertRowFromFeatureFS(ctx context.Context, txn bob.Tx, table string, sorted_columns []string, feature *response.Feature, org_id int32) error {
|
||||
// Create the query to produce the main row
|
||||
var sb strings.Builder
|
||||
sb.WriteString("INSERT INTO ")
|
||||
sb.WriteString(table)
|
||||
sb.WriteString(" (")
|
||||
for _, field := range sorted_columns {
|
||||
sb.WriteString(field)
|
||||
sb.WriteString(",")
|
||||
}
|
||||
// Specially add the geometry values since they aren't in the fields
|
||||
sb.WriteString("geometry_x,geometry_y,organization_id,updated")
|
||||
sb.WriteString(")\nVALUES (")
|
||||
for _, field := range sorted_columns {
|
||||
sb.WriteString("@")
|
||||
sb.WriteString(field)
|
||||
sb.WriteString(",")
|
||||
}
|
||||
// Specially add the geometry values since they aren't in the fields
|
||||
sb.WriteString("@geometry_x,@geometry_y,@organization_id,@updated)")
|
||||
|
||||
args := pgx.NamedArgs{}
|
||||
for k, v := range feature.Attributes {
|
||||
args[k] = v
|
||||
}
|
||||
// specially add geometry since it isn't in the list of attributes
|
||||
//args["geometry_x"] = feature.Geometry.X
|
||||
//args["geometry_y"] = feature.Geometry.Y
|
||||
args["organization_id"] = org_id
|
||||
args["updated"] = time.Now()
|
||||
|
||||
_, err := txn.ExecContext(ctx, sb.String(), args)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Failed to insert row into %s: %w", table, err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func hasUpdates(row map[string]string, feature response.Feature) bool {
|
||||
return false
|
||||
/*
|
||||
for key, value := range feature.Attributes {
|
||||
rowdata := row[strings.ToLower(key)]
|
||||
// We'll accept any 'nil' as represented by the empty string in the database
|
||||
if value == nil {
|
||||
if rowdata == "" {
|
||||
continue
|
||||
} else if len(rowdata) > 0 {
|
||||
return true
|
||||
} else {
|
||||
log.Error().Msg("Looks like our original value is nil, but our row value is something non-empty with a zero length. Need a programmer to look into this.")
|
||||
}
|
||||
}
|
||||
// check strings first, their simplest
|
||||
if featureAsString, ok := value.(response.TextValue); ok {
|
||||
if featureAsString.String() != rowdata {
|
||||
return true
|
||||
}
|
||||
continue
|
||||
} else if featureAsInt, ok := value.(response.Int32Value); ok {
|
||||
// Previously had a nil value, now we have a real value
|
||||
if rowdata == "" {
|
||||
return true
|
||||
}
|
||||
rowAsInt, err := strconv.Atoi(rowdata)
|
||||
if err != nil {
|
||||
log.Error().Msg(fmt.Sprintf("Failed to convert '%s' to an int to compare against %v for %v", rowdata, featureAsInt, key))
|
||||
}
|
||||
if rowAsInt != featureAsInt.V {
|
||||
return true
|
||||
} else {
|
||||
continue
|
||||
}
|
||||
} else if featureAsFloat, ok := value.(Float64Value); ok {
|
||||
// Previously had a nil value, now we have a real value
|
||||
if rowdata == "" {
|
||||
return true
|
||||
}
|
||||
rowAsFloat, err := strconv.ParseFloat(rowdata, 64)
|
||||
if err != nil {
|
||||
log.Error().Msg(fmt.Sprintf("Failed to convert '%s' to a float64 to compare against %v for %v", rowdata, featureAsFloat, key))
|
||||
}
|
||||
if rowAsFloat != featureAsFloat {
|
||||
return true
|
||||
} else {
|
||||
continue
|
||||
}
|
||||
}
|
||||
log.Error().Str("key", key).Str("rowdata", rowdata).Msg("we've hit a point where we can't tell if we have an update or not, need a programmer to look at the above")
|
||||
}
|
||||
return false
|
||||
*/
|
||||
}
|
||||
func updateRowFromFeature(ctx context.Context, table string, sorted_columns []string, feature *response.Feature, org_id int32) error {
|
||||
return nil
|
||||
/*
|
||||
// Get the current highest version for the row in question
|
||||
history_table := toHistoryTable(table)
|
||||
var sb strings.Builder
|
||||
sb.WriteString("SELECT MAX(version) FROM ")
|
||||
sb.WriteString(history_table)
|
||||
sb.WriteString(" WHERE OBJECTID=@objectid")
|
||||
|
||||
args := pgx.NamedArgs{}
|
||||
o := feature.Attributes["OBJECTID"].(float64)
|
||||
args["objectid"] = int(o)
|
||||
|
||||
var version int
|
||||
if err := db.PGInstance.PGXPool.QueryRow(ctx, sb.String(), args).Scan(&version); err != nil {
|
||||
return fmt.Errorf("Failed to query for version: %w", err)
|
||||
}
|
||||
|
||||
txn, err := db.PGInstance.BobDB.BeginTx(ctx, nil)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Unable to start transaction")
|
||||
}
|
||||
defer txn.Rollback(ctx)
|
||||
|
||||
err = insertRowFromFeatureHistory(ctx, txn, table, sorted_columns, feature, org_id, version+1)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Failed to insert history: %w", err)
|
||||
}
|
||||
err = updateRowFromFeatureFS(ctx, txn, table, sorted_columns, feature)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Failed to update row from feature: %w", err)
|
||||
}
|
||||
|
||||
txn.Commit(ctx)
|
||||
return nil
|
||||
*/
|
||||
}
|
||||
func insertRowFromFeatureHistory(ctx context.Context, transaction bob.Tx, table string, sorted_columns []string, feature *response.Feature, org_id int32, version int) error {
|
||||
history_table := toHistoryTable(table)
|
||||
var sb strings.Builder
|
||||
sb.WriteString("INSERT INTO ")
|
||||
sb.WriteString(history_table)
|
||||
sb.WriteString(" (")
|
||||
for _, field := range sorted_columns {
|
||||
sb.WriteString(field)
|
||||
sb.WriteString(",")
|
||||
}
|
||||
// Specially add the geometry values since they aren't in the fields
|
||||
sb.WriteString("created,geometry_x,geometry_y,organization_id,version")
|
||||
sb.WriteString(")\nVALUES (")
|
||||
for _, field := range sorted_columns {
|
||||
sb.WriteString("@")
|
||||
sb.WriteString(field)
|
||||
sb.WriteString(",")
|
||||
}
|
||||
// Specially add the geometry values since they aren't in the fields
|
||||
sb.WriteString("@created,@geometry_x,@geometry_y,@organization_id,@version)")
|
||||
args := pgx.NamedArgs{}
|
||||
for k, v := range feature.Attributes {
|
||||
args[k] = v
|
||||
}
|
||||
args["created"] = time.Now()
|
||||
args["organization_id"] = org_id
|
||||
args["version"] = version
|
||||
if _, err := transaction.ExecContext(ctx, sb.String(), args); err != nil {
|
||||
return fmt.Errorf("Failed to insert history row into %s: %w", table, err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func selectAllFromQueryResult(table string, sorted_columns []string) string {
|
||||
var sb strings.Builder
|
||||
sb.WriteString("SELECT * FROM ")
|
||||
sb.WriteString(table)
|
||||
sb.WriteString(" WHERE OBJECTID=ANY(@objectids)")
|
||||
return sb.String()
|
||||
}
|
||||
func toHistoryTable(table string) string {
|
||||
return "History_" + table[3:]
|
||||
}
|
||||
|
||||
func updateRowFromFeatureFS(ctx context.Context, transaction bob.Tx, table string, sorted_columns []string, feature *response.Feature) error {
|
||||
// Create the query to produce the main row
|
||||
var sb strings.Builder
|
||||
sb.WriteString("UPDATE ")
|
||||
sb.WriteString(table)
|
||||
sb.WriteString(" SET ")
|
||||
for _, field := range sorted_columns {
|
||||
// OBJECTID is special as our primary key, so skip it
|
||||
if field == "OBJECTID" {
|
||||
continue
|
||||
}
|
||||
sb.WriteString(field)
|
||||
sb.WriteString("=@")
|
||||
sb.WriteString(field)
|
||||
sb.WriteString(",")
|
||||
}
|
||||
// Specially add the geometry values since they aren't in the fields
|
||||
sb.WriteString("geometry_x=@geometry_x,geometry_y=@geometry_y,updated=@updated WHERE OBJECTID=@OBJECTID")
|
||||
|
||||
args := pgx.NamedArgs{}
|
||||
for k, v := range feature.Attributes {
|
||||
args[k] = v
|
||||
}
|
||||
// specially add geometry since it isn't in the list of attributes
|
||||
//args["geometry_x"] = feature.Geometry.X
|
||||
//args["geometry_y"] = feature.Geometry.Y
|
||||
args["updated"] = time.Now()
|
||||
|
||||
_, err := transaction.ExecContext(ctx, sb.String(), args)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Failed to update row into %s: %w", table, err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func exportFieldseekerLayer(ctx context.Context, group pond.ResultTaskGroup[SyncStats], org *models.Organization, fssync *fieldseeker.FieldSeeker, layer response.Layer) (SyncStats, error) {
|
||||
var stats SyncStats
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue