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

Merging active pull requests #19

Open
raihan2006i opened this issue Mar 22, 2023 · 2 comments
Open

Merging active pull requests #19

raihan2006i opened this issue Mar 22, 2023 · 2 comments
Assignees

Comments

@raihan2006i
Copy link
Owner

@ndbroadbent As far I know you have merged all the open PRs into your fork. Is it possible to merge your fork and close the open PRs?

@ndbroadbent
Copy link
Collaborator

Hi @raihan2006i, yes I'm still using this gem actively. Sure, please feel free to merge my fork and close the open PRs.

I've also noticed a performance problem with the "Non Archived" count that was causing issues for me with requests timing out. It is this line of code: https://github.com/raihan2006i/active_admin_paranoia/blob/master/lib/active_admin_paranoia/dsl.rb#L47

I have paranoia set up to add the "deleted_at" scope by default to all my models, so this was doubling the WHERE clause, e.g.

SELECT COUNT(*) FROM "users" WHERE "users"."deleted_at" IS NULL AND "users"."deleted_at" IS NULL

For some reason this really confused Postgres and prevented it from using the index, so the query did a full table scan that took over 2 minutes (for some tables).

I've added the same unscope(:where => archived_at_column) here (from the following line):

scope(I18n.t('active_admin_paranoia.non_archived'), default: true) { |scope| scope.unscope(:where => archived_at_column).where(archived_at_column => not_archived_value) }

This clears any existing scope that uses the deleted_at column before adding it again. In my case I could just use scope by itself, but I can see how this would support other use-cases where the condition isn't added by default.

So that commit is in my fork as well

@ndbroadbent
Copy link
Collaborator

Another quick update (just posting on this issue instead of opening a new one) - we actually ran into a performance problem with a table that had a few million rows. I think I was wrong with the comment above, and I just need to fully disable the counts for the "Archived" and "Non-Archived" tabs.

I couldn't figure out how to make this configurable, so I've just added show_count: false for now:

      scope(I18n.t('active_admin_paranoia.non_archived'), default: true, show_count: false) { |scope| scope.unscope(:where => archived_at_column).where(archived_at_column => not_archived_value) }
      scope(I18n.t('active_admin_paranoia.archived'), show_count: false) { |scope| scope.unscope(:where => archived_at_column).where.not(archived_at_column => not_archived_value) }

It would be nice if this gem could expose this somehow as a configuration option

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants