Guest User

Untitled

a guest
May 12th, 2019
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.78 KB | None | 0 0
  1. # SUMMARY
  2.  
  3. 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.
  4.  
  5. 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.
  6.  
  7. 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.
  8.  
  9. lynnbaine@gmail.com
  10. member id: 520
  11. active_subscription_id: nil
  12.  
  13. dtaylorbarrera@gmail.com
  14. member_id: 35
  15. active_subscription_id: 212
  16.  
  17. michaeljlacquamd@yahoo.com
  18. member_id: 519
  19. active_subscription_id: nil
  20.  
  21. # 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.
  22.  
  23. # PROPOSED SOLUTION
  24. update active_subcription_ids of members' with active subscriptions
  25.  
  26.  
  27. # SOURCE CODE
  28.  
  29. # Upcoming renewal query
  30.  
  31. https://github.com/JumpThru/a1000strong/blob/master/app/controllers/cms/members_controller.rb#L4
  32.  
  33. active_ids = Member.all.map(&:active_subscription_id)
  34. if params[:q].present?
  35. @users = Subscription.includes(:member).where("subscriptions.id in (?)", active_ids).by_keyword(params[:q]).limit(20)
  36. else
  37. @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)
  38. @previous_renewals = Subscription.includes(:member).by_keyword(params[:q]).order("subscriptions.id DESC").limit(20)
  39. end
  40.  
  41. # updating subscription
  42.  
  43. https://github.com/JumpThru/a1000strong/blob/master/app/controllers/cms/subscriptions_controller.rb#L6
  44.  
  45.  
  46. # RECORDS
  47.  
  48. # from old dumped db in my local; lynnbaine@gmail.com and michaeljlacquamd@yahoo.com doesn't have active_subcription_ids
  49.  
  50. # member's id
  51. 2.3.0 :067 > Member.find(519).email
  52. Member Load (0.4ms) SELECT "members".* FROM "members" WHERE "members"."id" = $1 LIMIT 1 [["id", 519]]
  53. => "michaeljlacquamd@yahoo.com"
  54. 2.3.0 :068 > Member.find(520).email
  55. Member Load (0.4ms) SELECT "members".* FROM "members" WHERE "members"."id" = $1 LIMIT 1 [["id", 520]]
  56. => "lynnbaine@gmail.com"
  57.  
  58. # no active_subscription_id
  59. 2.3.0 :069 > Member.find(520).active_subscription_id
  60. Member Load (0.4ms) SELECT "members".* FROM "members" WHERE "members"."id" = $1 LIMIT 1 [["id", 520]]
  61. => nil
  62. 2.3.0 :070 > Member.find(519).active_subscription_id
  63. Member Load (0.6ms) SELECT "members".* FROM "members" WHERE "members"."id" = $1 LIMIT 1 [["id", 519]]
  64. => nil
  65.  
  66.  
  67. # from prod; lynnbaine@gmail.com and michaeljlacquamd@yahoo.com already have active_subcription_ids
  68.  
  69. irb(main):001:0> Member.find(519).email
  70. => "michaeljlacquamd@yahoo.com"
  71. irb(main):002:0> Member.find(520).email
  72. => "lynnbaine@gmail.com"
  73. irb(main):003:0> Member.find(520).active_subscription_id
  74. => 465
  75. irb(main):004:0> Member.find(519).active_subscription_id
  76. => 463
  77.  
  78.  
  79. # 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'
  80.  
  81. irb(main):005:0> Subscription.where(member_id: 520)
  82. => #<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>]>
  83. irb(main):006:0> Subscription.where(member_id: 519)
  84.  
  85. => #<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>]>
  86.  
  87.  
  88. # from prod; dtaylorbarrera@gmail.com's active_subscription_id 212 has active_until date of may 15 2018
  89.  
  90. Subscription.find(212)
  91. => #<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>
  92.  
  93. # from prod; other members w/o active_subscription_ids but have subscription records with active status
  94.  
  95. irb(main):034:0> ha=_
  96. => [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]
  97. irb(main):035:0> ha.count
  98. => 86
  99.  
  100. # sample
  101.  
  102. irb(main):036:0> Member.find(557).active_subscription_id
  103. => nil
  104.  
  105. irb(main):037:0> Member.find(557).subscriptions
  106. => #<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>]>
  107.  
  108. # from prod; members w/o active_subscription_ids but have subscription records with active status which subscriptions are not FREE
  109.  
  110. irb(main):053:0> not_free.count
  111. => 54
  112.  
  113. irb(main):047:0> not_free =_
  114. => [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]
  115.  
  116.  
  117. # sample; member 543 will not be included in the upcoming renewal list in cms because he doesn't have active_subscription_id
  118.  
  119. irb(main):051:0> Member.find(543).active_subscription_id
  120. => nil
  121. irb(main):052:0> Member.find(543).subscriptions
  122. => #<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