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

Query Giving Errors w/ Distinct & Order By Random() + Missing Keyword Error #5

Open
weallwegot opened this issue Jul 18, 2020 · 1 comment

Comments

@weallwegot
Copy link

weallwegot commented Jul 18, 2020

Hi, thanks for this plugin!

i wanted to fork it to make some feature updates but ran into a couple issues while trying to figure out the code:

  • this query in mixer.rb is giving me an issue because of the Distinct & Random() combination, but I don't know enough about ruby or Active Record to fix it
      a_users, *b_users = users
        .real
        .not_suspended
        .activated
        .order("RANDOM()")
        .in_groups(SiteSetting.mingle_group_size)

turns into this raw SQL

SELECT DISTINCT "users".* FROM "users" INNER JOIN "group_users" ON "group_users"."user_id" = "users"."id" INNER JOIN "groups" ON "groups"."id" = "group_users"."group_id" WHERE "groups"."name" = 'trust_level_1' AND (users.id > 0) AND (NOT EXISTS(
                     SELECT 1
                     FROM anonymous_users a
                     WHERE a.user_id = users.id
                  )) AND (suspended_till IS NULL OR suspended_till <= '2020-07-18 05:11:27.079563') AND "users"."active" = TRUE ORDER BY RANDOM()

which gives this error:

Job exception: PG::InvalidColumnReference: ERROR:  for SELECT DISTINCT, ORDER BY expressions must appear in select list
LINE 5: ...11:27.079563') AND "users"."active" = TRUE ORDER BY RANDOM()

when i debugged this using the data explorer plugin, i found the query works okay without the DISTINCT included, but I'm not sure how to get that into ActiveRecord / ruby syntax.. any help?

& totally unrelated but i also got a missing keyword at error from this line in mingle.rb

module Jobs
  class Mingle < ::Jobs::Base
    sidekiq_options queue: :low

    def execute(args = {})
      return if !SiteSetting.mingle_enabled
      return log_mismingle unless mingle_sets.presence
      mingle_sets.each { |pair| ::Mingle::Sender.new(pair.compact).send! }
     ensure
       ::Mingle::Scheduler.new.reschedule!
    end
@weallwegot
Copy link
Author

actually missing keyword thing should be fine with this part i copied from elsewhere i think, ya?

at = SiteSetting.mingle_interval_number.send(SiteSetting.mingle_interval_type).from_now
::Mingle::Scheduler.new.reschedule!(at: at)

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

No branches or pull requests

1 participant