Skip to content
This repository was archived by the owner on Dec 13, 2024. It is now read-only.

Commit 76d18c6

Browse files
author
thisisaaronland
committed
add SQLiteFeaturesIndexRelationsFuncWithOptions
1 parent 744932f commit 76d18c6

File tree

1 file changed

+34
-9
lines changed

1 file changed

+34
-9
lines changed

index.go

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ import (
1010
"github.com/whosonfirst/go-whosonfirst-geojson-v2/feature"
1111
wof_index "github.com/whosonfirst/go-whosonfirst-index"
1212
"github.com/whosonfirst/go-whosonfirst-sqlite"
13-
"github.com/whosonfirst/go-whosonfirst-uri"
1413
wof_tables "github.com/whosonfirst/go-whosonfirst-sqlite-features/tables"
1514
sql_index "github.com/whosonfirst/go-whosonfirst-sqlite-index"
15+
"github.com/whosonfirst/go-whosonfirst-uri"
1616
"github.com/whosonfirst/warning"
1717
"io"
1818
"io/ioutil"
@@ -24,6 +24,11 @@ type SQLiteFeaturesLoadRecordFuncOptions struct {
2424
StrictAltFiles bool
2525
}
2626

27+
type SQLiteFeaturesIndexRelationsFuncOptions struct {
28+
Reader reader.Reader
29+
Strict bool
30+
}
31+
2732
func SQLiteFeaturesLoadRecordFunc(opts *SQLiteFeaturesLoadRecordFuncOptions) sql_index.SQLiteIndexerLoadRecordFunc {
2833

2934
cb := func(ctx context.Context, fh io.Reader, args ...interface{}) (interface{}, error) {
@@ -82,8 +87,16 @@ func SQLiteFeaturesLoadRecordFunc(opts *SQLiteFeaturesLoadRecordFuncOptions) sql
8287

8388
func SQLiteFeaturesIndexRelationsFunc(r reader.Reader) sql_index.SQLiteIndexerPostIndexFunc {
8489

90+
opts := &SQLiteFeaturesIndexRelationsFuncOptions{}
91+
opts.Reader = r
92+
93+
return SQLiteFeaturesIndexRelationsFuncWithOptions(opts)
94+
}
95+
96+
func SQLiteFeaturesIndexRelationsFuncWithOptions(opts *SQLiteFeaturesIndexRelationsFuncOptions) sql_index.SQLiteIndexerPostIndexFunc {
97+
8598
seen := new(sync.Map)
86-
99+
87100
cb := func(ctx context.Context, db sqlite.Database, tables []sqlite.Table, record interface{}) error {
88101

89102
geojson_t, err := wof_tables.NewGeoJSONTable()
@@ -137,7 +150,7 @@ func SQLiteFeaturesIndexRelationsFunc(r reader.Reader) sql_index.SQLiteIndexerPo
137150
}
138151

139152
seen.Store(id, true)
140-
153+
141154
sql := fmt.Sprintf("SELECT COUNT(id) FROM %s WHERE id=?", geojson_t.Name())
142155
row := conn.QueryRow(sql, id)
143156

@@ -158,10 +171,16 @@ func SQLiteFeaturesIndexRelationsFunc(r reader.Reader) sql_index.SQLiteIndexerPo
158171
return err
159172
}
160173

161-
fh, err := r.Read(ctx, rel_path)
174+
fh, err := opts.Reader.Read(ctx, rel_path)
162175

163-
if err != nil{
164-
return err
176+
if err != nil {
177+
178+
if opts.Strict {
179+
return err
180+
}
181+
182+
log.Printf("Failed to read '%s' because '%v'. Strict mode is disabled so skipping\n", rel_path, err)
183+
continue
165184
}
166185

167186
defer fh.Close()
@@ -170,9 +189,15 @@ func SQLiteFeaturesIndexRelationsFunc(r reader.Reader) sql_index.SQLiteIndexerPo
170189

171190
// check for warnings in case this record has a non-standard
172191
// placetype (20201224/thisisaaronland)
173-
174-
if err != nil && !warning.IsWarning(err){
175-
return err
192+
193+
if err != nil && !warning.IsWarning(err) {
194+
195+
if opts.Strict {
196+
return err
197+
}
198+
199+
log.Printf("Failed to load feature for '%s' because '%v'. Strict mode is disabled so skipping\n", rel_path, err)
200+
continue
176201
}
177202

178203
to_index = append(to_index, ancestor)

0 commit comments

Comments
 (0)