Giter VIP home page Giter VIP logo

Comments (3)

ddnexus avatar ddnexus commented on June 6, 2024 1

@riyasagrya Reproducing your case is impossible unless you provide an actual support and data, as indicated in the issue template itself.

Your queries are quite complex and it's not even evident what is the difference between the two.

At least you should troubleshoot your queries in order to isolate the bit that causes your problem and either you will find the issue on the way, or you will simplify it to a manageable and easy reproducible case, that can be properly re-posted.

from pagy.

riyasagrya avatar riyasagrya commented on June 6, 2024

@ddnexus

SELECT email_lists.*, json_agg(vendor_bills.* order by vendor_bills.created_at desc) as bills FROM email_lists left join email_bills on email_bills.email_list_id = email_lists.id left join vendor_bills on vendor_bills.id = email_bills.vendor_bill_id WHERE email_lists.email_user_id = '21034557-3516-4f7f-b980-7335ec3b1196' GROUP BY email_lists.id ORDER BY email_lists.name

[#<Pagy:0x000000013ece3288
  @count=26,
  @from=1,
  @in=26,
  @items=50,
  @last=1,
  @next=nil,
  @offset=0,
  @outset=0,
  @overflow=false,
  @page=1,
  @pages=1,
  @params={},
  @prev=nil,
  @to=26,
  @vars=
   {:page=>1,
    :items=>50,
    :outset=>0,
    :size=>[1, 4, 4, 1],
    :page_param=>:page,
    :params=>{},
    :fragment=>"",
    :link_extra=>"",
    :i18n_key=>"pagy.item_name",
    :cycle=>false,
    :metadata=>[:scaffold_url, :first_url, :prev_url, :page_url, :next_url, :last_url, :count, :page, :items, :vars, :pages, :last, :in, :from, :to, :prev, :next, :series],
    :overflow=>:last_page,
    :steps=>false,
    :count=>26}>,
 [#<EmailList:0x000000013de7bf38
   id: "dece4545-6c0c-469d-9c62-f1358adc02ae",
   email_user_id: "21034557-3516-4f7f-b980-7335ec3b1196",
   organization_id: "3e6ab6b2-5cb6-4dab-9943-791358c456a9",
   email: "[email protected]",
   last_bill_date: nil,
   fetch: true,
   created_at: Thu, 18 Aug 2022 16:19:19.123595000 UTC +00:00,
   updated_at: Thu, 16 Nov 2023 09:59:02.325684000 UTC +00:00,
   expense_category_id: "870574a3-c03c-4eec-b83c-8d2c15ed3c80",
   creator_id: "a50f8d55-ffc6-4e2f-b629-b69418e5cc1e",
   destroyer_id: nil,
   name: "ACT Fibernet",
   vendor_id: nil>,
  #<EmailList:0x000000013de7bda8
   id: "5a0afe05-0b3e-4689-b963-f324a77492a5",
   email_user_id: "21034557-3516-4f7f-b980-7335ec3b1196",
   organization_id: "3e6ab6b2-5cb6-4dab-9943-791358c456a9",
   email: "[email protected]",
   last_bill_date: nil,
   fetch: true,
   created_at: Thu, 18 Aug 2022 16:19:19.123595000 UTC +00:00,
   updated_at: Thu, 16 Nov 2023 09:59:02.325684000 UTC +00:00,
   expense_category_id: "870574a3-c03c-4eec-b83c-8d2c15ed3c80",
   creator_id: "a50f8d55-ffc6-4e2f-b629-b69418e5cc1e",
   destroyer_id: nil,
   name: "Airtel",
   vendor_id: nil>, and the list goes on....

The above is the first query and its result.

SELECT email_lists.*, coalesce(entities.name, email_lists.name) name, json_agg(vendor_bills.* order by vendor_bills.created_at desc) as bills FROM email_lists left join email_bills on email_bills.email_list_id = email_lists.id left join vendor_bills on vendor_bills.id = email_bills.vendor_bill_id left join entities on email_lists.vendor_id = entities.id WHERE email_lists.email_user_id = '21034557-3516-4f7f-b980-7335ec3b1196' GROUP BY email_lists.id, entities.name ORDER BY entities.name

[#<Pagy:0x000000013dc82038
  @count=1,
  @from=1,
  @in=1,
  @items=50,
  @last=1,
  @next=nil,
  @offset=0,
  @outset=0,
  @overflow=false,
  @page=1,
  @pages=1,
  @params={},
  @prev=nil,
  @to=1,
  @vars=
   {:page=>1,
    :items=>50,
    :outset=>0,
    :size=>[1, 4, 4, 1],
    :page_param=>:page,
    :params=>{},
    :fragment=>"",
    :link_extra=>"",
    :i18n_key=>"pagy.item_name",
    :cycle=>false,
    :metadata=>[:scaffold_url, :first_url, :prev_url, :page_url, :next_url, :last_url, :count, :page, :items, :vars, :pages, :last, :in, :from, :to, :prev, :next, :series],
    :overflow=>:last_page,
    :steps=>false,
    :count=>1}>,
 [#<EmailList:0x000000012bc54eb0
   id: "034d9e88-f29e-4ebc-bedf-a58efd165b0f",
   email_user_id: "21034557-3516-4f7f-b980-7335ec3b1196",
   organization_id: "3e6ab6b2-5cb6-4dab-9943-791358c456a9",
   email: "[email protected]",
   last_bill_date: nil,
   fetch: true,
   created_at: Thu, 18 Aug 2022 16:19:19.123595000 UTC +00:00,
   updated_at: Thu, 16 Nov 2023 09:59:02.325684000 UTC +00:00,
   expense_category_id: "a81ba26d-3751-44b5-bd8a-f6090b25e797",
   creator_id: "a50f8d55-ffc6-4e2f-b629-b69418e5cc1e",
   destroyer_id: nil,
   name: "Dineout",
   vendor_id: nil>,
  #<EmailList:0x000000012bc54cf8
   id: "04796b29-ebbb-4c96-b74d-6555455bbbea",
   email_user_id: "21034557-3516-4f7f-b980-7335ec3b1196",
   organization_id: "3e6ab6b2-5cb6-4dab-9943-791358c456a9",
   email: "[email protected]",
   last_bill_date: Wed, 27 Jul 2022,
   fetch: false,
   created_at: Thu, 18 Aug 2022 16:19:35.556650000 UTC +00:00,
   updated_at: Thu, 02 Nov 2023 05:11:29.337151000 UTC +00:00,
   expense_category_id: nil,
   creator_id: "760326e4-ba65-496a-aa67-60f6840444ba",
   destroyer_id: nil,
   name: nil,
   vendor_id: nil>,
  #<EmailList:0x000000012bc54b40
   id: "05bbc357-adb8-4923-8380-04cbd4d54289",
   email_user_id: "21034557-3516-4f7f-b980-7335ec3b1196",
   organization_id: "3e6ab6b2-5cb6-4dab-9943-791358c456a9",
   email: "[email protected]",
   last_bill_date: nil,
   fetch: true,
   created_at: Thu, 18 Aug 2022 16:19:19.123595000 UTC +00:00,
   updated_at: Thu, 16 Nov 2023 09:59:02.325684000 UTC +00:00,
   expense_category_id: "a81ba26d-3751-44b5-bd8a-f6090b25e797",
   creator_id: "a50f8d55-ffc6-4e2f-b629-b69418e5cc1e",
   destroyer_id: nil,
   name: "Swiggy",
   vendor_id: nil>, and the list goes on...

Here in this second query, the result contains count as 1 and the list has more than 1 activerecord entity.

You can see the count difference in both the queries

Please help me in this.

from pagy.

ddnexus avatar ddnexus commented on June 6, 2024

FYI: The above is not helpful at all.

Pagy gets the count by calling your_collection_scope.count(:all), which is an AR call.

AR may get the wrong count with complex queries, especially when group and order are involved: that is not a pagy bug, but a known AR issue.

If that is your problem, then you can solve it by reading and applying the doc.

Anyway if you still think it's a pagy bug, then you can repost a properly reproducible issue.

from pagy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.