Skip to content

Commit

Permalink
cache tgn requests
Browse files Browse the repository at this point in the history
  • Loading branch information
joecorall committed Aug 30, 2024
1 parent 865c09a commit 461cb2d
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func readCSVWithJSONTags(filePath string) (map[string]bool, []map[string][]strin
var rows []map[string][]string
newHeaders := map[string]bool{}
newCsv := &workbench.SheetsCsv{}
tgnCache := make(map[string]string)
for {
record, err := reader.Read()
if err != nil {
Expand Down Expand Up @@ -86,6 +87,11 @@ func readCSVWithJSONTags(filePath string) (map[string]bool, []map[string][]strin
}
str = strings.TrimLeft(str, "0")
case "field_subject_hierarchical_geo":
if _, ok := tgnCache[str]; ok {
str = tgnCache[str]
break
}

tgn, err := tgn.GetLocationFromTGN(str)
if err != nil {
return nil, nil, fmt.Errorf("unknown TGN: %s %v", str, err)
Expand All @@ -95,7 +101,8 @@ func readCSVWithJSONTags(filePath string) (map[string]bool, []map[string][]strin
if err != nil {
return nil, nil, fmt.Errorf("error marshalling TGN: %s %v", str, err)
}
str = string(locationJSON)
tgnCache[str] = string(locationJSON)
str = tgnCache[str]

case "field_rights":
switch str {
Expand Down

0 comments on commit 461cb2d

Please sign in to comment.