Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # SUMMARY
- Query for upcoming renewals states that member's subscription id must be included in active_ids or the list of all members' active_subscription_ids. Since lynnbaine@gmail.com and michaeljlacquamd@yahoo.com doesn't have active_subscription_ids, no luck for them to be included in the query results.
- As for dtaylorbarrera@gmail.com, the active_subscription_id in his record(id: 212) has active_until date of Mon, 14 May 2018 13:13:18 UTC +00:00 which doesn't satisfy this part of our query below (.where("active_until >= ? AND active_until <= ? AND subscriptions.id in (?)", Date.current, Date.current+1.month, active_ids). See records below.
- Upon checking, there were 86 other members that has no active_subscription_ids but has subscription records with "Active" status. 54 of them have subscriptions that are not FREE. Some will be renewed soon this year.
- lynnbaine@gmail.com
- member id: 520
- active_subscription_id: nil
- dtaylorbarrera@gmail.com
- member_id: 35
- active_subscription_id: 212
- michaeljlacquamd@yahoo.com
- member_id: 519
- active_subscription_id: nil
- # NOTE: Got these records above from old dumped db in my local. Currently lynnbaine@gmail.com and michaeljlacquamd@yahoo.com already have active_subscription_ids. These active_subscription_ids seem to be added when their subscriptions were updated last may 12. Updating member's subscription updates active_subscription_ids in their record, see source code. Not sure if this is made manually but this might mean that prior to may 12 (issue raised may 10, Friday) these 2 doesn't have active_subscription_ids just like the old records are showing. See records below.
- # PROPOSED SOLUTION
- update active_subcription_ids of members' with active subscriptions
- # SOURCE CODE
- # Upcoming renewal query
- https://github.com/JumpThru/a1000strong/blob/master/app/controllers/cms/members_controller.rb#L4
- active_ids = Member.all.map(&:active_subscription_id)
- if params[:q].present?
- @users = Subscription.includes(:member).where("subscriptions.id in (?)", active_ids).by_keyword(params[:q]).limit(20)
- else
- @upcomings = Subscription.includes(:member).where("active_until >= ? AND active_until <= ? AND subscriptions.id in (?)", Date.current, Date.current+1.month, active_ids).order("subscriptions.active_until ASC").by_keyword(params[:q]).limit(20)
- @previous_renewals = Subscription.includes(:member).by_keyword(params[:q]).order("subscriptions.id DESC").limit(20)
- end
- # updating subscription
- https://github.com/JumpThru/a1000strong/blob/master/app/controllers/cms/subscriptions_controller.rb#L6
- # RECORDS
- # from old dumped db in my local; lynnbaine@gmail.com and michaeljlacquamd@yahoo.com doesn't have active_subcription_ids
- # member's id
- 2.3.0 :067 > Member.find(519).email
- Member Load (0.4ms) SELECT "members".* FROM "members" WHERE "members"."id" = $1 LIMIT 1 [["id", 519]]
- => "michaeljlacquamd@yahoo.com"
- 2.3.0 :068 > Member.find(520).email
- Member Load (0.4ms) SELECT "members".* FROM "members" WHERE "members"."id" = $1 LIMIT 1 [["id", 520]]
- => "lynnbaine@gmail.com"
- # no active_subscription_id
- 2.3.0 :069 > Member.find(520).active_subscription_id
- Member Load (0.4ms) SELECT "members".* FROM "members" WHERE "members"."id" = $1 LIMIT 1 [["id", 520]]
- => nil
- 2.3.0 :070 > Member.find(519).active_subscription_id
- Member Load (0.6ms) SELECT "members".* FROM "members" WHERE "members"."id" = $1 LIMIT 1 [["id", 519]]
- => nil
- # from prod; lynnbaine@gmail.com and michaeljlacquamd@yahoo.com already have active_subcription_ids
- irb(main):001:0> Member.find(519).email
- => "michaeljlacquamd@yahoo.com"
- irb(main):002:0> Member.find(520).email
- => "lynnbaine@gmail.com"
- irb(main):003:0> Member.find(520).active_subscription_id
- => 465
- irb(main):004:0> Member.find(519).active_subscription_id
- => 463
- # from prod; lynnbaine@gmail.com and michaeljlacquamd@yahoo.com's subscriptions were updated last may 12 which causes their active_subscription_id to be updated. see 'updated_at'
- irb(main):005:0> Subscription.where(member_id: 520)
- => #<ActiveRecord::Relation [#<Subscription id: 465, member_id: 520, plan_name: "MEMBER - $1,000", amount_paid: #<BigDecimal:558a3575c820,'0.1E4',9(18)>, created_at: "2018-05-16 16:58:43", updated_at: "2019-05-12 12:04:25", status: "Active", active_until: "2019-05-20 00:00:00", card_id: "card_1CSSxYHVXp4Z3vzp3rAH0sBM", customer_id: "cus_CsDOtnxAKXcDXt", charge_id: "ch_1CSSxaHVXp4Z3vzpXvYCTLkG", enable_renewal: true, enable_login: true>]>
- irb(main):006:0> Subscription.where(member_id: 519)
- => #<ActiveRecord::Relation [#<Subscription id: 463, member_id: 519, plan_name: "MEMBER - $1,000", amount_paid: #<BigDecimal:558a35738470,'0.1E4',9(18)>, created_at: "2018-05-15 23:11:51", updated_at: "2019-05-12 12:03:59", status: "Active", active_until: "2019-05-20 00:00:00", card_id: "card_1CSCJ6HVXp4Z3vzpMm2WfqQF", customer_id: "cus_CrwBNgbCzG2tBT", charge_id: "ch_1CSCJ8HVXp4Z3vzp2dnnuXUv", enable_renewal: true, enable_login: true>]>
- # from prod; dtaylorbarrera@gmail.com's active_subscription_id 212 has active_until date of may 15 2018
- Subscription.find(212)
- => #<Subscription id: 212, member_id: 35, plan_name: "ACTIVE INVESTOR - $2,500", amount_paid: #<BigDecimal:558a35703c48,'0.25E4',9(18)>, created_at: "2017-05-14 13:13:18", updated_at: "2017-05-14 13:13:18", status: "Active", active_until: "2018-05-14 13:13:18", card_id: "card_1AJMX9HVXp4Z3vzpNBmDSRXb", customer_id: "cus_AefsphQqHtqIsr", charge_id: "ch_1AJMXAHVXp4Z3vzpk8Rw7fnk", enable_renewal: true, enable_login: true>
- # from prod; other members w/o active_subscription_ids but have subscription records with active status
- irb(main):034:0> ha=_
- => [614, 631, 665, 521, 528, 526, 595, 535, 536, 529, 617, 616, 596, 673, 533, 597, 620, 619, 667, 621, 622, 668, 669, 518, 523, 524, 531, 538, 537, 540, 541, 542, 553, 544, 547, 546, 624, 543, 549, 545, 550, 159, 552, 554, 556, 555, 193, 557, 670, 558, 625, 548, 671, 560, 593, 666, 594, 598, 599, 600, 672, 626, 601, 602, 604, 551, 534, 559, 530, 522, 627, 527, 628, 605, 629, 607, 606, 608, 610, 539, 611, 630, 612, 618, 613, 664]
- irb(main):035:0> ha.count
- => 86
- # sample
- irb(main):036:0> Member.find(557).active_subscription_id
- => nil
- irb(main):037:0> Member.find(557).subscriptions
- => #<ActiveRecord::Associations::CollectionProxy [#<Subscription id: 570, member_id: 557, plan_name: "FREE", amount_paid: #<BigDecimal:558a3501d730,'0.0',9(18)>, created_at: "2018-10-11 01:20:46", updated_at: "2018-10-11 01:20:46", status: "Active", active_until: "2019-10-11 01:20:46", card_id: nil, customer_id: nil, charge_id: nil, enable_renewal: true, enable_login: true>]>
- # from prod; members w/o active_subscription_ids but have subscription records with active status which subscriptions are not FREE
- irb(main):053:0> not_free.count
- => 54
- irb(main):047:0> not_free =_
- => [665, 616, 596, 673, 533, 620, 667, 622, 669, 518, 523, 524, 531, 538, 537, 553, 624, 543, 549, 545, 550, 159, 552, 554, 556, 555, 193, 558, 625, 548, 666, 594, 599, 600, 672, 601, 602, 551, 534, 559, 530, 522, 627, 527, 605, 607, 606, 608, 610, 539, 630, 612, 618, 664]
- # sample; member 543 will not be included in the upcoming renewal list in cms because he doesn't have active_subscription_id
- irb(main):051:0> Member.find(543).active_subscription_id
- => nil
- irb(main):052:0> Member.find(543).subscriptions
- => #<ActiveRecord::Associations::CollectionProxy [#<Subscription id: 536, member_id: 543, plan_name: "ACTIVE INVESTOR - $2,500", amount_paid: #<BigDecimal:558a32eb9198,'0.25E4',9(18)>, created_at: "2018-07-23 00:11:39", updated_at: "2018-07-23 00:11:39", status: "Active", active_until: "2019-07-23 00:11:39", card_id: "card_1CqreGHVXp4Z3vzpRCiqF8gC", customer_id: "cus_DHQVZnn1WM9PxX", charge_id: "ch_1CqreHHVXp4Z3vzpQamLIz9m", enable_renewal: true, enable_login: true>]>
Add Comment
Please, Sign In to add comment