Creating a plugin to override QUERY_RESULT_MAX_LIMIT

I naively attempted to create a plugin (which I’ve never done, other than running through the plugin tutorial some years ago) to override the limits set in the DataExplorer module, however I’m not getting it to work.

Am I on the right track or is this a completely wrong approach?

Note: I am setting the QUERY_RESULT_DEFAULT_LIMIT to 1 to make it easier to test if the custom limits are taking effect.

I recommend against a plugin here.

Instead submit a PR to add a GlobalSetting (which is backed by environment)

5 Likes

Apparently this hasn’t been a high priority for ranyone in the past 2 years, but I needed this today and solved it by editing the file by hand inside the container.

A workaround is something like the below in app.yml:

  after_bundle_exec:
   - replace:
        filename: "/var/www/discourse/plugins/discourse-data-explorer/plugin.rb"
        from: /QUERY_RESULT_MAX_LIMIT = 10_000/
        to: QUERY_RESULT_MAX_LIMIT = 100_000

But it looks like the PR would be something like adding this to plugin.rb:

GlobalSetting.add_default(:query_result_max_limit, 10000)

and then changing the above module to something like

  QUERY_RESULT_MAX_LIMIT = GlobalSetting.query_result_max_limit || 10_000

Is that all it would take?

2 Likes

Close…

I would stop using the constant and instead use GlobalSetting.query_result_max_limit everywhere, you are already configuring a default, why configure it twice.

But there needs to be a default if they don’t set the GlobalSetting?

You set it, in plugin.rb

OHHHHHH. I guess “add_default” does, in fact, add a default. :person_shrugging:

Oops.

So add the default GlobalSetting and replace all of the references to the old constant with the GlobalSetting.

Got it.

I’ll see what I can do.