Skip to content

Commit

Permalink
Speedrun: remove "level-subcategories".
Browse files Browse the repository at this point in the history
  • Loading branch information
stefansundin committed Jan 14, 2021
1 parent d2a9eed commit 1ab1599
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 25 deletions.
26 changes: 6 additions & 20 deletions app/speedrun.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,33 +18,19 @@ def self.resolve_id(type, id)
return @@cache[type][id] if @@cache[type][id]
value = $redis.get("speedrun:#{type}:#{id}")
if value
@@cache[type][id] = if type == "level-subcategories"
JSON.parse(value)
else
value
end
return @@cache[type][id]
@@cache[type][id] = value
return value
end

if type == "game"
response = get("/games/#{id}")
raise(SpeedrunError, response) if !response.success?
redis_value = value = response.json["data"]["names"]["international"]
elsif type == "level-subcategories"
response = get("/levels/#{id}/variables")
raise(SpeedrunError, response) if !response.success?
value = response.json["data"].select { |var| var["is-subcategory"] }.to_h do |var|
[
var["id"],
var["values"]["values"].to_h do |id, val|
[id, val["label"]]
end
]
end
redis_value = value.to_json
value = response.json["data"]["names"]["international"]
else
raise "unsupported type"
end

$redis.set("speedrun:#{type}:#{id}", redis_value)
$redis.set("speedrun:#{type}:#{id}", value)
@@cache[type][id] = value
return value
end
Expand Down
5 changes: 0 additions & 5 deletions views/speedrun.atom.erb
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,6 @@
platform = run["platform"]["data"]["name"]
platform += " (#{run["region"]["data"]["name"]})" if run["system"]["region"]
end

if !run["level"]["data"].empty?
level_subcategories = Speedrun.resolve_id("level-subcategories", run["level"]["data"]["id"])
category += level_subcategories.select { |id, values| run["values"].has_key?(id) }.map { |id, values| " - " + values[run["values"][id]] }.join
end
-%>

<entry>
Expand Down

0 comments on commit 1ab1599

Please sign in to comment.