Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PERFORMANCE] resource index_query executed twice? #3223

Closed
4 of 11 tasks
pjmuller opened this issue Sep 5, 2024 · 3 comments
Closed
4 of 11 tasks

[PERFORMANCE] resource index_query executed twice? #3223

pjmuller opened this issue Sep 5, 2024 · 3 comments

Comments

@pjmuller
Copy link

pjmuller commented Sep 5, 2024

Describe the bug

When I load the INDEX view for a resource I always see 2 queries triggered
one with LIMIT 11 and one with LIMIT 31 (the latter is the one I would expect).

2 examples

Avo::Table Load (0.3ms)  SELECT "avo_tables".* FROM "avo_tables" WHERE "avo_tables"."tenant_id" = $1 /* loading for inspect */ ORDER BY "avo_tables"."position" ASC LIMIT $2  [["tenant_id", "dev_org"], ["LIMIT", 11]]
Avo::Table Load (0.3ms)  SELECT "avo_tables".* FROM "avo_tables" WHERE "avo_tables"."tenant_id" = $1 AND "avo_tables"."section" = $2 ORDER BY "avo_tables"."position" ASC, avo_tables.created_at desc LIMIT $3 OFFSET $4  [["tenant_id", "dev_org"], ["section", "participants"], ["LIMIT", 31], ["OFFSET", 0]]
City Load (2.4ms)  SELECT "cities"."id", "cities"."postal_code", "cities"."city_name", "cities"."created_at", "cities"."created_by_admin_id" FROM "cities" WHERE "cities"."tenant_id" = $1 AND "cities"."deleted_at" IS NULL /* loading for inspect */ LIMIT $2  [["tenant_id", "dev_org"], ["LIMIT", 11]]
City Load (0.2ms)  SELECT "cities"."id", "cities"."postal_code", "cities"."city_name", "cities"."created_at", "cities"."created_by_admin_id" FROM "cities" WHERE "cities"."tenant_id" = $1 AND "cities"."deleted_at" IS NULL ORDER BY created_at asc NULLS LAST LIMIT $2 OFFSET $3  [["tenant_id", "dev_org"], ["LIMIT", 31], ["OFFSET", 0]]

Steps to Reproduce

I have this in every resource I have

Expected behavior & Actual behavior

Only run the actual query

Models and resource files

System configuration

Avo version: 3.12.0

Rails version: 7.2.1

Ruby version: 3.2.2

License type:

  • Community
  • Pro
  • Advanced

Are you using Avo monkey patches, overriding views or view components?

  • Yes. If so, please post code samples.
  • No

Impact

  • High impact (It makes my app un-usable.)
  • Medium impact (I'm annoyed, but I'll live.)
  • Low impact (It's really a tiny thing that I could live with.)

Urgency

  • High urgency (I can't continue development without it.)
  • Medium urgency (I found a workaround, but I'd love to have it fixed.)
  • Low urgency (It can wait. I just wanted you to know about it.)
@Paul-Bob
Copy link
Contributor

Paul-Bob commented Sep 5, 2024

I'm not able to reproduce it. (Got something)

I noticed that in both your examples there is this comment present: /* loading for inspect */

@Paul-Bob
Copy link
Contributor

Paul-Bob commented Sep 5, 2024

I thought I got it but I don't. I'm not able to reproduce it, could you please share the whole log like this:

web    | Started GET "/admin/resources/events" for 127.0.0.1 at 2024-09-05 17:31:41 +0300
web    |   User Load (0.6ms)  SELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT $2  [["id", 39], ["LIMIT", 1]]
web    | Processing by Avo::EventsController#index as HTML
web    |   Event Count (0.5ms)  SELECT COUNT(*) FROM "events"
web    |   Event Load (0.7ms)  SELECT "events".* FROM "events" ORDER BY events.created_at desc LIMIT $1 OFFSET $2  [["LIMIT", 3], ["OFFSET", 0]]
web    | Completed 200 OK in 221ms (Views: 175.9ms | ActiveRecord: 1.1ms (2 queries, 0 cached) | GC: 63.6ms)

@Paul-Bob
Copy link
Contributor

Paul-Bob commented Sep 6, 2024

Since /* loading for inspect */ is present I guess you're inspecting the query somewhere or something else is triggering that inspect.

Tried with several resources and can't reproduce it.

The limit of 11 appears to be applied here https://github.com/rails/rails/blob/main/activerecord/lib/active_record/relation.rb#L1286

I'm closing this one since it seems to be something specific to your application, however, let me know if I can help you further.

@Paul-Bob Paul-Bob closed this as completed Sep 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

No branches or pull requests

2 participants