{"action":"created","issue":{"url":"https://api.github.com/repos/OCA/OCB/issues/271","labels_url":"https://api.github.com/repos/OCA/OCB/issues/271/labels{/name}","comments_url":"https://api.github.com/repos/OCA/OCB/issues/271/comments","events_url":"https://api.github.com/repos/OCA/OCB/issues/271/events","html_url":"https://github.com/OCA/OCB/pull/271","id":92391460,"number":271,"title":"Use display_name instead of CASE... WHEN... in partner name_search()","user":{"login":"mdietrichc2c","id":7628281,"avatar_url":"https://avatars.githubusercontent.com/u/7628281?v=3","gravatar_id":"","url":"https://api.github.com/users/mdietrichc2c","html_url":"https://github.com/mdietrichc2c","followers_url":"https://api.github.com/users/mdietrichc2c/followers","following_url":"https://api.github.com/users/mdietrichc2c/following{/other_user}","gists_url":"https://api.github.com/users/mdietrichc2c/gists{/gist_id}","starred_url":"https://api.github.com/users/mdietrichc2c/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mdietrichc2c/subscriptions","organizations_url":"https://api.github.com/users/mdietrichc2c/orgs","repos_url":"https://api.github.com/users/mdietrichc2c/repos","events_url":"https://api.github.com/users/mdietrichc2c/events{/privacy}","received_events_url":"https://api.github.com/users/mdietrichc2c/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-07-01T13:54:22Z","updated_at":"2015-07-01T14:00:38Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/OCA/OCB/pulls/271","html_url":"https://github.com/OCA/OCB/pull/271","diff_url":"https://github.com/OCA/OCB/pull/271.diff","patch_url":"https://github.com/OCA/OCB/pull/271.patch"},"body":"Copied from https://github.com/odoo/odoo/pull/7399.\r\n\r\nThis PR is to use the field `display_name` (which is added in the module `account_report_company` in 7.0) in the partner `name_search()` function, as done in 8.0 here: https://github.com/odoo/odoo/blob/8.0/openerp/addons/base/res/res_partner.py#L658-L699\r\n\r\nThis allows for better performance than the existing PostgreSQL `CASE...` currently in `base`."},"comment":{"url":"https://api.github.com/repos/OCA/OCB/issues/comments/117684827","html_url":"https://github.com/OCA/OCB/pull/271#issuecomment-117684827","issue_url":"https://api.github.com/repos/OCA/OCB/issues/271","id":117684827,"user":{"login":"guewen","id":417223,"avatar_url":"https://avatars.githubusercontent.com/u/417223?v=3","gravatar_id":"","url":"https://api.github.com/users/guewen","html_url":"https://github.com/guewen","followers_url":"https://api.github.com/users/guewen/followers","following_url":"https://api.github.com/users/guewen/following{/other_user}","gists_url":"https://api.github.com/users/guewen/gists{/gist_id}","starred_url":"https://api.github.com/users/guewen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/guewen/subscriptions","organizations_url":"https://api.github.com/users/guewen/orgs","repos_url":"https://api.github.com/users/guewen/repos","events_url":"https://api.github.com/users/guewen/events{/privacy}","received_events_url":"https://api.github.com/users/guewen/received_events","type":"User","site_admin":false},"created_at":"2015-07-01T14:00:37Z","updated_at":"2015-07-01T14:00:37Z","body":":+1: \r\nThe original query below is really slow (we have an average execution time of 3s on a database here) and could be drastically improved using the stored `display_name` field.\r\n\r\n```sql\r\nSELECT\r\n    res_partner.id\r\nFROM\r\n    res_partner\r\nLEFT\r\n    JOIN res_partner company ON res_partner.parent_id = company.id\r\nWHERE (\r\n    \"res_partner\".\"active\" = '' )\r\n    AND (\r\n        res_partner.email ILIKE ''\r\n        OR CASE\r\n            WHEN company.id IS NULL\r\n            OR res_partner.is_company THEN res_partner.name\r\n            ELSE company.name || '' || res_partner.name\r\n        END ILIKE '' )\r\nORDER BY\r\n    CASE\r\n        WHEN company.id IS NULL\r\n        OR res_partner.is_company THEN res_partner.name\r\n        ELSE company.name || '' || res_partner.name\r\n    END\r\nLIMIT 0;\r\n```"}}