Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Opt in Acquire Lite Apps
opt_ins = []
App.find_each do |app|
if app.can_use_feature?(:welcome_message) && !app.can_use_feature?(:visitor_auto_messaging) && PermittedLanguage.where(app_id: app.id).count > 1
opt_ins << app.id
end
end
opt_ins
app = a 6
admin = app.admins.where(email: 'serena@intercom.io').first
feature = Feature.fetch_by_name('acquire-lite-localisation-support')
feature.opt_in_apps(opt_ins, admin)
@aidanlynch
Copy link

aidanlynch commented Sep 26, 2016

Can we replace PermittedLanguage.where(app_id: app.id).where.not(locale: app.locale).count > 0 with
PermittedLanguage.where(app_id: app.id).count > 1

We can also use:

THE_FEATURE = '<your feature name>'
AppFeatureOptIn.opt_in(THE_FEATURE, opt_ins, admin) 
AppFeatureOptIn.where(feature_name: THE_FEATURE).count

@agerlic
Copy link

agerlic commented Sep 26, 2016

PermittedLanguage.where(app_id: app.id).count can you check if this query uses an index ?
otherwise, could we load all PermittedLanguage with one query in memory ? eg : permittedlanguages = PermittedLanguage.all

@serenaf
Copy link
Author

serenaf commented Sep 26, 2016

@agerlic This query uses the index on index_permitted_languages_on_app_id_and_locale see expplain output of local dev environment:

`1 | SIMPLE | permitted_languages | ref | index_permitted_languages_on_app_id_and_locale | index_permitted_languages_on_app_id_and_locale | 4 | const | 1 | Using index``

@serenaf
Copy link
Author

serenaf commented Sep 26, 2016

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