Skip to content

Commit ec04c72

Browse files
committed
Flattened global penalty field to array instead of a mapping with one key
1 parent 8424653 commit ec04c72

File tree

5 files changed

+56
-6
lines changed

5 files changed

+56
-6
lines changed

app/resources/api/v3/public/restriction_resource.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def verdicts
1717
{ 'banned': @model.banned_cards.pluck(:card_id),
1818
'restricted': @model.restricted_cards.pluck(:card_id),
1919
'universal_faction_cost': Hash[@model.universal_faction_cost_cards.pluck(:value, :card_id).group_by(&:first).map{ |k,a| [k,a.map(&:last)] }],
20-
'global_penalty': Hash[@model.global_penalty_cards.pluck(:value, :card_id).group_by(&:first).map{ |k,a| [k,a.map(&:last)] }],
20+
'global_penalty': @model.global_penalty_cards.pluck(:card_id),
2121
'points': Hash[@model.points_cards.pluck(:value, :card_id).group_by(&:first).map{ |k,a| [k,a.map(&:last)] }]
2222
}
2323
end
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class UpdateUnifiedRestrictionsToVersion4 < ActiveRecord::Migration[7.0]
2+
def change
3+
update_view :unified_restrictions, materialized: true, version: 4, revert_to_version: 3
4+
end
5+
end

db/schema.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#
1111
# It's strongly recommended that you check this file into your version control system.
1212

13-
ActiveRecord::Schema[7.0].define(version: 2022_09_23_032558) do
13+
ActiveRecord::Schema[7.0].define(version: 2022_09_25_113944) do
1414
# These are extensions that must be enabled in order to support this database
1515
enable_extension "plpgsql"
1616

@@ -195,7 +195,6 @@
195195
create_table "restrictions_cards_global_penalty", id: false, force: :cascade do |t|
196196
t.text "restriction_id", null: false
197197
t.text "card_id", null: false
198-
t.integer "value", null: false
199198
t.datetime "created_at", null: false
200199
t.datetime "updated_at", null: false
201200
end
@@ -301,7 +300,6 @@
301300
ELSE false
302301
END AS is_restricted,
303302
COALESCE(restrictions_cards_points.value, 0) AS eternal_points,
304-
COALESCE(restrictions_cards_global_penalty.value, 0) AS global_penalty,
305303
COALESCE(restrictions_cards_universal_faction_cost.value, 0) AS universal_faction_cost
306304
FROM ((((((cards_cross_restrictions_and_snapshots
307305
JOIN card_pools_cards ON (((card_pools_cards.card_pool_id = cards_cross_restrictions_and_snapshots.card_pool_id) AND (card_pools_cards.card_id = (cards_cross_restrictions_and_snapshots.card_id)::text))))

db/views/unified_restrictions_v04.sql

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
WITH cards_cross_restrictions_and_snapshots AS (
2+
SELECT
3+
cards.id as card_id,
4+
restrictions.id as restriction_id,
5+
snapshots.id as snapshot_id,
6+
snapshots.format_id as format_id,
7+
snapshots.card_pool_id as card_pool_id,
8+
snapshots.date_start as snapshot_date_start
9+
FROM
10+
cards, restrictions JOIN snapshots ON restrictions.id = snapshots.restriction_id
11+
)
12+
SELECT
13+
cards_cross_restrictions_and_snapshots.format_id,
14+
cards_cross_restrictions_and_snapshots.card_pool_id,
15+
cards_cross_restrictions_and_snapshots.snapshot_id,
16+
cards_cross_restrictions_and_snapshots.snapshot_date_start,
17+
cards_cross_restrictions_and_snapshots.restriction_id,
18+
cards_cross_restrictions_and_snapshots.card_id,
19+
restrictions_cards_banned.restriction_id IS NOT NULL
20+
OR restrictions_cards_restricted.restriction_id IS NOT NULL
21+
OR restrictions_cards_points.restriction_id IS NOT NULL
22+
OR restrictions_cards_global_penalty.restriction_id IS NOT NULL
23+
OR restrictions_cards_universal_faction_cost.restriction_id IS NOT NULL
24+
as in_restriction,
25+
CASE WHEN restrictions_cards_banned.restriction_id IS NOT NULL THEN true ELSE false END AS is_banned,
26+
CASE WHEN restrictions_cards_restricted.restriction_id IS NOT NULL THEN true ELSE false END AS is_restricted,
27+
COALESCE(restrictions_cards_points.value, 0) AS eternal_points,
28+
COALESCE(restrictions_cards_universal_faction_cost.value, 0) AS universal_faction_cost
29+
FROM
30+
cards_cross_restrictions_and_snapshots
31+
JOIN card_pools_cards ON card_pools_cards.card_pool_id = cards_cross_restrictions_and_snapshots.card_pool_id
32+
AND card_pools_cards.card_id = cards_cross_restrictions_and_snapshots.card_id
33+
LEFT OUTER JOIN restrictions_cards_banned ON
34+
restrictions_cards_banned.restriction_id = cards_cross_restrictions_and_snapshots.restriction_id
35+
AND restrictions_cards_banned.card_id = cards_cross_restrictions_and_snapshots.card_id
36+
LEFT OUTER JOIN restrictions_cards_points ON
37+
restrictions_cards_points.restriction_id = cards_cross_restrictions_and_snapshots.restriction_id
38+
AND restrictions_cards_points.card_id = cards_cross_restrictions_and_snapshots.card_id
39+
LEFT OUTER JOIN restrictions_cards_global_penalty ON
40+
restrictions_cards_global_penalty.restriction_id = cards_cross_restrictions_and_snapshots.restriction_id
41+
AND restrictions_cards_global_penalty.card_id = cards_cross_restrictions_and_snapshots.card_id
42+
LEFT OUTER JOIN restrictions_cards_restricted ON
43+
restrictions_cards_restricted.restriction_id = cards_cross_restrictions_and_snapshots.restriction_id
44+
AND restrictions_cards_restricted.card_id = cards_cross_restrictions_and_snapshots.card_id
45+
LEFT OUTER JOIN restrictions_cards_universal_faction_cost ON
46+
restrictions_cards_universal_faction_cost.restriction_id = cards_cross_restrictions_and_snapshots.restriction_id
47+
AND restrictions_cards_universal_faction_cost.card_id = cards_cross_restrictions_and_snapshots.card_id
48+
;

lib/tasks/cards.rake

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -578,8 +578,7 @@ namespace :cards do
578578
cards.each do |card|
579579
global_penalty << RestrictionCardGlobalPenalty.new(
580580
restriction_id: r['id'],
581-
card_id: card,
582-
value: cost
581+
card_id: card
583582
)
584583
end
585584
end

0 commit comments

Comments
 (0)