Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add location information to timeline #59

Merged
merged 8 commits into from
Aug 12, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions db/migrations/000012_add_gps_coords.down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ALTER TABLE infos DROP COLUMN "longitude" text;
ALTER TABLE infos DROP COLUMN "latitude" text;
ALTER TABLE infos DROP COLUMN "location" text;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rgeo seems to be fast enough that the location text itself might not even need to be cached? In my quick profiling the reverse geocoding almost doesn't show up. Instead it could happen at "layout-time".

Copy link
Owner

@SmilyOrg SmilyOrg May 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Types are not needed while dropping columns.

Suggested change
ALTER TABLE infos DROP COLUMN "longitude" text;
ALTER TABLE infos DROP COLUMN "latitude" text;
ALTER TABLE infos DROP COLUMN "location" text;
ALTER TABLE infos DROP COLUMN "longitude";
ALTER TABLE infos DROP COLUMN "latitude";
ALTER TABLE infos DROP COLUMN "location";

3 changes: 3 additions & 0 deletions db/migrations/000012_add_gps_coords.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ALTER TABLE infos ADD COLUMN "longitude" numeric;
ALTER TABLE infos ADD COLUMN "latitude" numeric;
ALTER TABLE infos ADD COLUMN "location" text;
5 changes: 4 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ require (
github.com/golang-migrate/migrate/v4 v4.15.0-beta.1
github.com/gosimple/slug v1.10.0
github.com/hako/durafmt v0.0.0-20200605151348-3a43fc422dd9
github.com/imdario/mergo v0.3.12
github.com/imdario/mergo v0.3.13
github.com/joho/godotenv v1.3.0
github.com/karrick/godirwalk v1.15.6
github.com/kelindar/intmap v1.1.0
Expand All @@ -27,6 +27,7 @@ require (
github.com/prometheus/client_model v0.2.0
github.com/pyroscope-io/client v0.7.0
github.com/rwcarlsen/goexif v0.0.0-20190401172101-9e8deecbddbd
github.com/sams96/rgeo v1.2.0
github.com/sheerun/queue v1.0.1
github.com/tdewolff/canvas v0.0.0-20200504121106-e2600b35c365
github.com/x448/float16 v0.8.4
Expand All @@ -47,6 +48,7 @@ require (
github.com/fogleman/gg v1.2.1-0.20190220221249-0403632d5b90 // indirect
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect
github.com/golang/gddo v0.0.0-20210115222349-20d68f94ee1f // indirect
github.com/golang/geo v0.0.0-20200730024412-e86565bf3f35 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/go-cmp v0.5.7 // indirect
github.com/google/pprof v0.0.0-20210226084205-cbba55b83ad5 // indirect
Expand All @@ -69,6 +71,7 @@ require (
github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0 // indirect
github.com/tdewolff/minify/v2 v2.7.1-0.20200112204046-70870d25a935 // indirect
github.com/tdewolff/parse/v2 v2.4.2 // indirect
github.com/twpayne/go-geom v1.4.4 // indirect
github.com/wcharczuk/go-chart v2.0.2-0.20191206192251-962b9abdec2b+incompatible // indirect
go.uber.org/atomic v1.7.0 // indirect
golang.org/x/mod v0.4.2 // indirect
Expand Down
17 changes: 12 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG
github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
github.com/go-stack/stack v1.6.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
github.com/go-test/deep v1.1.0 h1:WOcxcdHcvdgThNXjw0t76K42FXTU7HpNQWHpA2HHNlg=
github.com/gobuffalo/attrs v0.0.0-20190224210810-a9411de4debd/go.mod h1:4duuawTqi2wkkpB4ePgWMaai6/Kc6WEz83bhFwpHzj0=
github.com/gobuffalo/depgen v0.0.0-20190329151759-d478694a28d3/go.mod h1:3STtPUQYuzV0gBVOY3vy6CfMm/ljR4pABfrTeHNLHUY=
github.com/gobuffalo/depgen v0.1.0/go.mod h1:+ifsuy7fhi15RWncXQQKjWS9JPkdah5sZvtHc2RXGlg=
Expand Down Expand Up @@ -243,6 +244,8 @@ github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 h1:DACJavvAHhabrF0
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k=
github.com/golang/gddo v0.0.0-20210115222349-20d68f94ee1f h1:16RtHeWGkJMc80Etb8RPCcKevXGldr57+LOyZt8zOlg=
github.com/golang/gddo v0.0.0-20210115222349-20d68f94ee1f/go.mod h1:ijRvpgDJDI262hYq/IQVYgf8hd8IHUs93Ol0kvMBAx4=
github.com/golang/geo v0.0.0-20200730024412-e86565bf3f35 h1:enTowfyfjtomBQhxX9mhUD+0tZhpe4rIzStO4aNlou8=
github.com/golang/geo v0.0.0-20200730024412-e86565bf3f35/go.mod h1:QZ0nwyI2jOfgRAoBvP+ab5aRr7c9x7lhGEJrKvBwjWI=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
Expand Down Expand Up @@ -349,8 +352,8 @@ github.com/hashicorp/hcl v0.0.0-20170914154624-68e816d1c783/go.mod h1:oZtUIOe8dh
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/imdario/mergo v0.3.12 h1:b6R2BslTbIEToALKP7LxUvijTsNI9TAe80pLWN2g/HU=
github.com/imdario/mergo v0.3.12/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA=
github.com/imdario/mergo v0.3.13 h1:lFzP57bqS/wsqKssCGmtLAb8A0wKjLGrve2q3PPVcBk=
github.com/imdario/mergo v0.3.13/go.mod h1:4lJ1jqUDcsbIECGy0RUJAXNIhg+6ocWgb1ALK2O4oXg=
github.com/inconshreveable/log15 v0.0.0-20170622235902-74a0988b5f80/go.mod h1:cOaXtrgN4ScfRrD9Bre7U1thNq5RtJ8ZoP4iXVGRj6o=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/jackc/chunkreader v1.0.0/go.mod h1:RT6O25fNZIuasFJRyZ4R/Y2BbhasbmZXF9QQ7T3kePo=
Expand Down Expand Up @@ -576,6 +579,8 @@ github.com/rs/zerolog v1.13.0/go.mod h1:YbFCdg8HfsridGWAh22vktObvhZbQsZXe4/zB0OK
github.com/rs/zerolog v1.15.0/go.mod h1:xYTKnLHcpfU2225ny5qZjxnj9NvkumZYjJHlAThCjNc=
github.com/rwcarlsen/goexif v0.0.0-20190401172101-9e8deecbddbd h1:CmH9+J6ZSsIjUK3dcGsnCnO41eRBOnY12zwkn5qVwgc=
github.com/rwcarlsen/goexif v0.0.0-20190401172101-9e8deecbddbd/go.mod h1:hPqNNc0+uJM6H+SuU8sEs5K5IQeKccPqeSjfgcKGgPk=
github.com/sams96/rgeo v1.2.0 h1:49cBHeXSADHGHYUsNByhzrzZXkOwYU4+/Vxv7lQn/mY=
github.com/sams96/rgeo v1.2.0/go.mod h1:ngWuABNhG1zT7afDMW5JGZHQgWeNUfPf8Ag5gaojKjA=
github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
github.com/sheerun/queue v1.0.1 h1:TIAQyN0aRRvrJcNa2beZFfxwuxrfXBc9Mj+UWDNH7Ao=
github.com/sheerun/queue v1.0.1/go.mod h1:YtjrWT5jymvCLo/lEWDk3sv7A1Kgj0qcl3SZx7Zmcfo=
Expand Down Expand Up @@ -608,7 +613,7 @@ github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UV
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
github.com/tdewolff/canvas v0.0.0-20200504121106-e2600b35c365 h1:iNyEAGvN8yNc5/maTbLhStXRIqp+PSxpjG68KRtU3Y4=
github.com/tdewolff/canvas v0.0.0-20200504121106-e2600b35c365/go.mod h1:DCuQBGs+Nm73wH9S/z1tlUKDbAPCGa6W7A/DHU1ENmQ=
github.com/tdewolff/minify/v2 v2.7.1-0.20200112204046-70870d25a935 h1:nRG5jPGtwJpQ8KtrqhGVdLAuOnk4YWfNxh4Kx9XMuAw=
Expand All @@ -618,6 +623,8 @@ github.com/tdewolff/parse/v2 v2.4.2/go.mod h1:WzaJpRSbwq++EIQHYIRTpbYKNA3gn9it1I
github.com/tdewolff/test v1.0.6 h1:76mzYJQ83Op284kMT+63iCNCI7NEERsIN8dLM+RiKr4=
github.com/tdewolff/test v1.0.6/go.mod h1:6DAvZliBAAnD7rhVgwaM7DE5/d9NMOAJ09SqYqeK4QE=
github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
github.com/twpayne/go-geom v1.4.4 h1:bcCPAvvNSzjmpUqR0Uqh39ClCKtPx6kZVR7EakQaVJI=
github.com/twpayne/go-geom v1.4.4/go.mod h1:Kz4sX4LtdesDQgkhsMERazLlH/NiCg90s6FPaNr0KNI=
github.com/ulikunitz/xz v0.5.6/go.mod h1:2bypXElzHzzJZwzH67Y6wb67pO62Rzfn7BSiF4ABRW8=
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/valyala/fasttemplate v1.0.1/go.mod h1:UQGH1tvbgY+Nz5t2n7tXsz52dQxojPUpymEIMZ47gx8=
Expand Down Expand Up @@ -1081,10 +1088,10 @@ gopkg.in/yaml.v2 v2.2.5/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.7/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
gopkg.in/yaml.v3 v3.0.0/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gorm.io/driver/postgres v1.0.8/go.mod h1:4eOzrI1MUfm6ObJU/UcmbXyiHSs8jSwH95G5P5dxcAg=
gorm.io/gorm v1.20.12/go.mod h1:0HFTzE/SqkGTzK6TlDPPQbAYCluiVvhzoA1+aVyzenw=
gorm.io/gorm v1.21.4/go.mod h1:0HFTzE/SqkGTzK6TlDPPQbAYCluiVvhzoA1+aVyzenw=
Expand Down
33 changes: 27 additions & 6 deletions internal/image/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"strings"
"sync"
"time"
"math"

"photofield/internal/clip"
"photofield/internal/metrics"
Expand Down Expand Up @@ -179,21 +180,27 @@ func (source *Database) writePendingInfosSqlite() {
defer upsertPrefix.Finalize()

updateMeta := conn.Prep(`
INSERT INTO infos(path_prefix_id, filename, width, height, orientation, created_at_unix, created_at_tz_offset)
INSERT INTO infos(path_prefix_id, filename, width, height, orientation, created_at_unix, created_at_tz_offset, latitude, longitude, location)
SELECT
id as path_prefix_id,
? as filename,
? as width,
? as height,
? orientation,
? as created_at_unix,
? as created_at_tz_offset
? as created_at_tz_offset,
? as latitude,
? as longitude,
? as location
FROM prefix
WHERE str == ?
ON CONFLICT(path_prefix_id, filename) DO UPDATE SET
width=excluded.width,
height=excluded.height,
orientation=excluded.orientation,
latitude=excluded.latitude,
longitude=excluded.longitude,
location=excluded.location,
created_at_unix=excluded.created_at_unix,
created_at_tz_offset=excluded.created_at_tz_offset;`)
defer updateMeta.Finalize()
Expand Down Expand Up @@ -297,7 +304,15 @@ func (source *Database) writePendingInfosSqlite() {
updateMeta.BindInt64(4, (int64)(imageInfo.Orientation))
updateMeta.BindInt64(5, imageInfo.DateTime.Unix())
updateMeta.BindInt64(6, int64(timezoneOffsetSeconds/60))
updateMeta.BindText(7, dir)
if math.IsNaN(imageInfo.Latitude) {
updateMeta.BindNull(7)
updateMeta.BindNull(8)
} else {
updateMeta.BindFloat(7, imageInfo.Latitude)
updateMeta.BindFloat(8, imageInfo.Longitude)
}
updateMeta.BindText(9, imageInfo.Location)
updateMeta.BindText(10, dir)

_, err := updateMeta.Step()
if err != nil {
Expand Down Expand Up @@ -423,7 +438,7 @@ func (source *Database) Get(id ImageId) (InfoResult, bool) {
defer source.pool.Put(conn)

stmt := conn.Prep(`
SELECT width, height, orientation, color, created_at
SELECT width, height, orientation, color, created_at, location
FROM infos
WHERE id == ?;`)
defer stmt.Reset()
Expand All @@ -450,6 +465,8 @@ func (source *Database) Get(id ImageId) (InfoResult, bool) {
info.DateTime, _ = time.Parse(dateFormat, stmt.ColumnText(4))
info.DateTimeNull = stmt.ColumnType(4) == sqlite.TypeNull

info.Location = stmt.ColumnText(5)

return info, true
}

Expand All @@ -461,7 +478,7 @@ func (source *Database) GetBatch(ids []ImageId) <-chan InfoListResult {
defer source.pool.Put(conn)

sql := `
SELECT id, width, height, orientation, color, created_at_unix, created_at_tz_offset
SELECT id, width, height, orientation, color, created_at_unix, created_at_tz_offset, location
FROM infos
WHERE id IN (`

Expand Down Expand Up @@ -504,6 +521,8 @@ func (source *Database) GetBatch(ids []ImageId) <-chan InfoListResult {
info.DateTime = time.Unix(unix, 0).In(time.FixedZone("tz_offset", timezoneOffset*60))
info.DateTimeNull = stmt.ColumnType(5) == sqlite.TypeNull

info.Location = stmt.ColumnText(7)

out <- info
}
close(out)
Expand Down Expand Up @@ -638,7 +657,7 @@ func (source *Database) List(dirs []string, options ListOptions) <-chan InfoList
defer source.pool.Put(conn)

sql := `
SELECT id, width, height, orientation, color, created_at_unix, created_at_tz_offset
SELECT id, width, height, orientation, color, created_at_unix, created_at_tz_offset, location
FROM infos
WHERE path_prefix_id IN (
SELECT id
Expand Down Expand Up @@ -713,6 +732,8 @@ func (source *Database) List(dirs []string, options ListOptions) <-chan InfoList
info.DateTime = time.Unix(unix, 0).In(time.FixedZone("tz_offset", timezoneOffset*60))
info.DateTimeNull = stmt.ColumnType(5) == sqlite.TypeNull

info.Location = stmt.ColumnText(7)

out <- info
}

Expand Down
27 changes: 25 additions & 2 deletions internal/image/exiftool-mostlygeek.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"strconv"
"strings"
"time"
"math"

"github.com/mostlygeek/go-exiftool"
)
Expand Down Expand Up @@ -54,6 +55,9 @@ func (decoder *ExifToolMostlyGeekLoader) DecodeInfo(path string, info *Info) err
"-TimeStamp",
"-FileModifyDate",
"-FileCreateDate",
// Location Info
"-GPSLatitude",
"-GPSLongitude",
)
if err != nil {
return err
Expand All @@ -63,6 +67,8 @@ func (decoder *ExifToolMostlyGeekLoader) DecodeInfo(path string, info *Info) err
rotation := ""
imageWidth := ""
imageHeight := ""
latitude := ""
longitude := ""

// var gpsTime time.Time

Expand All @@ -86,6 +92,11 @@ func (decoder *ExifToolMostlyGeekLoader) DecodeInfo(path string, info *Info) err
imageWidth = value
case "ImageHeight":
imageHeight = value
case "GPSLatitude":
latitude = value
case "GPSLongitude":
longitude = value

// case "GPSDateTime":
// gpsTime, _ = parseDateTime(value)
default:
Expand Down Expand Up @@ -131,12 +142,24 @@ func (decoder *ExifToolMostlyGeekLoader) DecodeInfo(path string, info *Info) err
info.Orientation = getOrientationFromRotation(rotation)
}

if latitude != "" {
info.Latitude, err = strconv.ParseFloat(latitude, 64)
if err != nil {
info.Latitude = math.NaN()
}
}

if longitude != "" {
info.Longitude, err = strconv.ParseFloat(longitude, 64)
if err != nil {
info.Longitude = math.NaN()
}
}

if info.Orientation.SwapsDimensions() {
info.Width, info.Height = info.Height, info.Width
}

// println(path, info.Width, info.Height, info.DateTime.String())

return nil
}

Expand Down
17 changes: 17 additions & 0 deletions internal/image/indexMetadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ package image

import (
"fmt"
"math"


)

func (source *Source) indexMetadata(in <-chan interface{}) {
Expand All @@ -16,6 +19,20 @@ func (source *Source) indexMetadata(in <-chan interface{}) {
fmt.Println("Unable to load image info meta", err, path)
continue
}

if !math.IsNaN(info.Latitude) {
loc, err := source.rg.ReverseGeocode([]float64{info.Longitude, info.Latitude})
if err != nil {
info.Location = ""
} else if loc.City == "" && loc.Country == "" {
info.Location = ""
} else if loc.City != "" {
info.Location = fmt.Sprintf("%s, %s, %s", loc.City, loc.Province, loc.Country)
} else {
info.Location = fmt.Sprintf("%s, %s", loc.Province, loc.Country)
}
}

source.database.Write(path, info, UpdateMeta)
source.imageInfoCache.Delete(id)
}
Expand Down
6 changes: 5 additions & 1 deletion internal/image/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,23 @@ type Info struct {
DateTime time.Time
Color uint32
Orientation Orientation
Latitude float64
Longitude float64
Location string
}

func (info *Info) Size() Size {
return Size{X: info.Width, Y: info.Height}
}

func (info *Info) String() string {
return fmt.Sprintf("width: %v, height: %v, date: %v, color: %08x, orientation: %s",
return fmt.Sprintf("width: %v, height: %v, date: %v, color: %08x, orientation: %s, location: %s",
info.Width,
info.Height,
info.DateTime.String(),
info.Color,
info.Orientation,
info.Location,
)
}

Expand Down
12 changes: 12 additions & 0 deletions internal/image/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import (
"github.com/docker/go-units"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"

"github.com/sams96/rgeo"
)

var ErrNotFound = errors.New("not found")
Expand Down Expand Up @@ -140,6 +142,7 @@ type Source struct {

decoder *Decoder
database *Database
rg *rgeo.Rgeo

imageInfoCache InfoCache
pathCache PathCache
Expand All @@ -161,6 +164,15 @@ func NewSource(config Config, migrations embed.FS, migrationsThumbs embed.FS) *S
source.database = NewDatabase(filepath.Join(config.DataDir, "photofield.cache.db"), migrations)
source.imageInfoCache = newInfoCache()
source.pathCache = newPathCache()

r, err := rgeo.New(rgeo.Provinces10, rgeo.Cities10)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This takes about half a minute to init on my (admittedly quite old) PC.

Maybe a good idea would be to load it async (e.g. in a goroutine) just so that restarts don't take that long?

Alternatively rgeo could be extended to use a sqlite file instead of JSON for the loading, or maybe even for the queries itself. Should be way faster :)


if err != nil {
// Handle error
fmt.Println("RGEO ERR", err)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
fmt.Println("RGEO ERR", err)
log.Fatalf("failed to init rgeo: %s", err)

} else {
source.rg = r
}

source.SourceLatencyHistogram = promauto.NewHistogramVec(prometheus.HistogramOpts{
Namespace: metrics.Namespace,
Expand Down
1 change: 1 addition & 0 deletions internal/layout/album.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type AlbumEvent struct {
LastOnDay bool
Elapsed time.Duration
Section Section
Location string
}

func LayoutAlbumEvent(layout Layout, rect render.Rect, event *AlbumEvent, scene *render.Scene, source *image.Source) render.Rect {
Expand Down
Loading