Open raihan2006i opened 1 year ago
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
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
@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?