-
Notifications
You must be signed in to change notification settings - Fork 4
/
warmup.go
48 lines (41 loc) · 1.2 KB
/
warmup.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package geopackage
import (
"errors"
"fmt"
"log"
"github.com/PDOK/gokoala/config"
"github.com/jmoiron/sqlx"
)
// warmUpFeatureTables executes a warmup query to speedup subsequent queries.
// This encompasses traversing index(es) to fill the local cache.
func warmUpFeatureTables(
configuredCollections config.GeoSpatialCollections,
featureTableByCollectionID map[string]*featureTable,
db *sqlx.DB) error {
for collID, table := range featureTableByCollectionID {
if table == nil {
return errors.New("given table can't be nil")
}
for _, coll := range configuredCollections {
if coll.ID == collID && coll.Features != nil {
if err := warmUpFeatureTable(table.TableName, db); err != nil {
return err
}
break
}
}
}
return nil
}
func warmUpFeatureTable(tableName string, db *sqlx.DB) error {
query := fmt.Sprintf(`
select minx,maxx,miny,maxy from %[1]s where minx <= 0 and maxx >= 0 and miny <= 0 and maxy >= 0
`, tableName)
log.Printf("start warm-up of feature table '%s'", tableName)
_, err := db.Exec(query)
if err != nil {
return fmt.Errorf("failed to warm-up feature table '%s': %w", tableName, err)
}
log.Printf("end warm-up of feature table '%s'", tableName)
return nil
}