Skip to content

Commit ce32ef9

Browse files
committed
remove caching from inveniordm search by slug
1 parent 41622b7 commit ce32ef9

4 files changed

Lines changed: 8 additions & 20 deletions

File tree

commonmeta/reader.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func NewReader(r io.Reader) *Reader {
2121
}
2222
}
2323

24-
const Version = "v0.32.0"
24+
const Version = "v0.32.1"
2525

2626
// ContributorRoles list of contributor roles defined in commonmeta schema.
2727
//

inveniordm/reader.go

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ import (
1515
"strconv"
1616
"time"
1717

18-
"github.com/muesli/cache2go"
19-
2018
"github.com/front-matter/commonmeta/authorutils"
2119
"github.com/front-matter/commonmeta/commonmeta"
2220
"github.com/front-matter/commonmeta/doiutils"
@@ -784,17 +782,10 @@ func SearchByDOI(doi string, client *InvenioRDMClient) (string, error) {
784782
}
785783

786784
// SearchBySlug searches InvenioRDM communities by slug.
787-
// Specify type of community (blog, topic or subject) in query, subject area communities are always queried.
788-
func SearchBySlug(slug string, type_ string, client *InvenioRDMClient, cache *cache2go.CacheTable) (string, error) {
789-
// first check for cached community ID
790-
res, _ := cache.Value(slug)
791-
if res != nil {
792-
id := fmt.Sprintf("%v", res.Data())
793-
return id, nil
794-
}
795-
785+
// Specify type of community (blog, topic or subject) in query.
786+
func SearchBySlug(slug string, type_ string, client *InvenioRDMClient) (string, error) {
796787
var query Query
797-
requestURL := fmt.Sprintf("https://%s/api/communities?q=slug:%s&type=%s&type=subject", client.Host, slug, type_)
788+
requestURL := fmt.Sprintf("https://%s/api/communities?q=slug:%s&type=%s", client.Host, slug, type_)
798789
req, _ := http.NewRequest(http.MethodGet, requestURL, nil)
799790
req.Header = http.Header{
800791
"Content-Type": {"application/json"},
@@ -814,7 +805,6 @@ func SearchBySlug(slug string, type_ string, client *InvenioRDMClient, cache *ca
814805
return "", nil
815806
} else {
816807
id := utils.ParseString(query.Hits.Hits[0].ID)
817-
cache.Add(slug, 1*time.Hour, id)
818808
return id, nil
819809
}
820810
}

inveniordm/reader_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"time"
77

88
"github.com/front-matter/commonmeta/inveniordm"
9-
"github.com/muesli/cache2go"
109
"golang.org/x/time/rate"
1110
)
1211

@@ -106,8 +105,7 @@ func ExampleSearchBySlug() {
106105
host := "rogue-scholar.org"
107106
rl := rate.NewLimiter(rate.Every(10*time.Second), 100)
108107
client := inveniordm.NewClient(rl, host)
109-
cache := cache2go.Cache("communities")
110-
s, _ := inveniordm.SearchBySlug("naturalSciences", "subject", client, cache)
108+
s, _ := inveniordm.SearchBySlug("naturalSciences", "subject", client)
111109
fmt.Println(s)
112110
// Output:
113111
// f04b2ef6-257d-4aa1-8fcb-83039a3a9471

inveniordm/writer.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ func Upsert(record commonmeta.APIResponse, client *InvenioRDMClient, cache *cach
453453
for i, v := range data.Relations {
454454
if v.Type == "IsPartOf" && strings.HasPrefix(v.ID, "https://rogue-scholar.org/api/communities/") {
455455
slug := strings.Split(v.ID, "/")[5]
456-
communityID, _ := SearchBySlug(slug, "blog", client, cache)
456+
communityID, _ := SearchBySlug(slug, "blog", client)
457457
if communityID != "" {
458458
record.Community = slug
459459
record.CommunityID = communityID
@@ -522,7 +522,7 @@ func Upsert(record commonmeta.APIResponse, client *InvenioRDMClient, cache *cach
522522
if synonym := CommunityTranslations[slug]; synonym != "" {
523523
slug = synonym
524524
}
525-
communityID, err = SearchBySlug(slug, "topic", client, cache)
525+
communityID, err = SearchBySlug(slug, "topic", client)
526526
if err != nil {
527527
fmt.Println(err)
528528
}
@@ -860,7 +860,7 @@ func UpsertCommunity(community Community, client *InvenioRDMClient, apiKey strin
860860
var communityID string
861861

862862
// check if community already exists
863-
communityID, _ = SearchBySlug(community.Slug, community.Metadata.Type.ID, client, cache)
863+
communityID, _ = SearchBySlug(community.Slug, community.Metadata.Type.ID, client)
864864
if communityID != "" {
865865
community.ID = communityID
866866
communityID, err = UpdateCommunity(community, client, apiKey)

0 commit comments

Comments
 (0)