ankane / blazer

Business intelligence made simple
MIT License
4.5k stars 470 forks source link

[Idea] Limit setting for queries #270

Open VicenteFava opened 4 years ago

VicenteFava commented 4 years ago

Hi,

What do you think about having a limit setting that applies to all the queries if it is set? The idea of this is to prevent the database or the server from having performance issues when executing queries that grab a large amount of data.

If you think that this can be helpful I can do a PR with the code. Thanks!

ankane commented 4 years ago

Hey @VicenteFava, thanks for the suggestion! For the database, it's best to set a statement timeout to limit the impact of individual queries. For the server, it'd be good to benchmark where most of the time is spent for large result sets to help decide what to do and test potential solutions. I think a row_limit option would likely help - we'd just need to make it clear to users when the results were limited (including for cached results).

joelvh commented 4 years ago

Hi @ankane, we are using Blazer for some visualizations as well as custom reports. We'd also like to have something like a row_limit for the web view, to limit results which are displayed (or maybe we think of it akin to pagination), while still indicating the total row count.

I've looked at the code and there are several ins and outs that make it hard to know the best place to introduce this limit. We're just looking for a limit on what is displayed in a tabular view. Limiting data for charts isn't a focus for us at the moment. Just tabular view, with the ability to then download the full results.

Could you give some pointers of where best to look at implementing this? I'm happy to put a PR together.

Thanks!

rdlugosz commented 3 years ago

A nice feature in addition to this would be to impose the row limits on the display version of the results, but allow for downloading the CSV of the full report results.

aki77 commented 3 years ago

311 PR has already addressed limiting the number of html views only.

Workman commented 2 years ago

@aki77 +1 to #311. It would be valuable to our team, too. We're forking to include it, but would prefer to stay on the core gem for updates.

@ankane Any thoughts or concerns regarding merging in #311 that would give you pause to merging it in?

tiagotex commented 2 years ago

I've come across the problem in my organization, is there plans to introduce this feature?

@Workman Is your fork public?

aki77 commented 2 years ago

Until the PRs are merged, I am using the following monkey patch.

_app/controllers/blazer/queriescontroller.rb

require Blazer::Engine.root.join('app/controllers/blazer/queries_controller.rb')

module BlazerQueriesControllerExtention
  def render_run
    if request.format == :html && Blazer.settings['row_limit']
      @row_limit ||= Blazer.settings['row_limit']
    end

    super
  end
end

Blazer::QueriesController.prepend(BlazerQueriesControllerExtention)

config/blazer.yml

row_limit: 5000