Skip to content

Commit c08b642

Browse files
committed
Cache calls to Hawt service endpoints
1 parent ecca52a commit c08b642

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

app/services/protips/hawt_service.rb

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,27 @@ def feature!
2121
url = URI.parse("#{ENV['PRIVATE_URL']}/api/v1/protips/feature.json").to_s
2222
protip_json = MultiJson.load(protip_hash.to_json)
2323

24-
RestClient.post(url, protip_json, accept: :json, content_type: 'application/json')
24+
Rails.cache.fetch(['hawt_feature', url, protip_hash[:public_id]], expires: 1.hour) do
25+
RestClient.post(url, protip_json, accept: :json, content_type: 'application/json')
26+
end
2527
end
2628

2729
def unfeature!
2830
url = URI.parse("#{ENV['PRIVATE_URL']}/api/v1/protips/unfeature.json").to_s
2931
protip_json = MultiJson.load(protip_hash.to_json)
3032

31-
RestClient.post(url, protip_json, accept: :json, content_type: 'application/json')
33+
Rails.cache.fetch(['hawt_unfeature', url, protip_hash[:public_id]], expires: 1.hour) do
34+
RestClient.post(url, protip_json, accept: :json, content_type: 'application/json')
35+
end
3236
end
3337

3438
def hawt?
3539
url = URI.parse("#{ENV['PRIVATE_URL']}/api/v1/protips/hawt.json").to_s
3640
protip_json = MultiJson.load(protip_hash.to_json)
3741

38-
JSON.parse(RestClient.post(url, protip_json, accept: :json, content_type: 'application/json').to_s)['hawt?']
42+
Rails.cache.fetch(['hawt_hawt', url, protip_hash[:public_id]], expires: 1.hour) do
43+
JSON.parse(RestClient.post(url, protip_json, accept: :json, content_type: 'application/json').to_s)['hawt?']
44+
end
3945
end
4046
end
4147

0 commit comments

Comments
 (0)