ruby-on-rails - rails : An efficient method to match subdomains in the database?

标签 ruby-on-rails algorithm postgresql activerecord performance

我们允许用户将域添加到事件记录模型(例如 User.domain),并使用 User.find_by_domain 按域查找用户。

将来我们希望允许用户输入 *.example.com 作为他们的域,并允许 User.find_by_subdomain('sub1.example.com') 和 User.find_by_subdomain('sub2.example.com') 工作.但是,如果用户不在模型中使用像 *.example.com 这样的通配符,我们也希望 example.com 直接匹配 example.com。我们需要能够说 User.find_by_subdomain('sub1.example.com') 而不是 User.find_by_subdomain('*.example.com')

这也必须与像 sub.example.co.uk 这样的域一起工作,我们理想情况下希望可以在数据库中运行的高效查询。避免特定于数据库的查询会很好,但 Postgres 是当前的生产数据库。

提前致谢,因为我们一直在为此绞尽脑汁。

最佳答案

关于ruby-on-rails - rails : An efficient method to match subdomains in the database?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3891179/

相关文章:

ruby-on-rails - cucumber 和 capybara 情景 session

ruby-on-rails - 如何在Rails中使用json更新nested_attributes?

algorithm - 在 Letterpress iOS 游戏中生成字母的合理算法是什么?

javascript - 找到任意两个数字的所有公因数的最有效方法

algorithm - 将字母和数字分开,使它们的相对顺序在 O(n) 时间和 O(1) 空间内保持不变

postgresql - 如何在 Prisma ORM 中过滤关系

ruby-on-rails - 身份验证后将 omniauth-facebook 重定向到特定页面

ruby-on-rails - 如何 Hook 销毁属于另一个模型的模型?

sql - PostgreSQL:我想知道 'cast'的区别

javascript - Sequelize 查询时间戳格式