Efficient external rostering with MySQL and ejabberd

做~自己de王妃 提交于 2019-12-02 19:39:36

IIUC, the table rosterusers is read-only from the POV of your eJabberd server app. This would make it simple, to replace it with a view, that creates the needed 2 row out of 1 row in your own friends table.

Not knowing the structure of your own friendship table, I can't give you the full code, but here is what I thought of as pseudo-SQL

CREATE VIEW rosterusers AS SELECT * FROM (
    SELECT 
        selfuser.name AS username, 
        frienduser.jid AS jid,
        -- ....,
        selfuser.jid AS jid_as_id
    FROM
        users AS selfuser
        INNER JOIN friendships ON ....
        INNER JOIN users AS frienduser ON ...
    UNION SELECT 
        frienduser.name AS username, 
        selfuser.jid AS jid,
        -- ....,
        frienduser.jid AS jid_as_id
    FROM
        users AS selfuser
        INNER JOIN friendships ON ....
        INNER JOIN users AS frienduser ON ...
);

and then

SELECT
    username, jid, subscription, ask, server, type
FROM rosterusers
WHERE jid_as_id='user1@myserver.org'

should give you 2 rows, one from each part of the UNION in the View

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!