Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/algorithm/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Rails:在数据库中匹配子域的有效方法?_Ruby On Rails_Algorithm_Postgresql_Activerecord_Performance - Fatal编程技术网

Ruby on rails Rails:在数据库中匹配子域的有效方法?

Ruby on rails Rails:在数据库中匹配子域的有效方法?,ruby-on-rails,algorithm,postgresql,activerecord,performance,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.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是当前的生产数据库


提前感谢您,因为我们已经绞尽脑汁想了一会儿了。

试试这样的优化:


尝试以下类似的优化:


我想我们可以,但这似乎是一个问题的一小部分,我相信它可以在数据库中轻松解决。设置sphinx/solr或任何其他索引器似乎有点过分?我想我们可以,但这似乎是问题的一小部分,我相信它可以在数据库中轻松解决。设置sphinx/solr或任何其他索引器似乎有点过头了?