-
Notifications
You must be signed in to change notification settings - Fork 428
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
mod_roster
backends rewrite
#139
mod_roster
backends rewrite
#139
Conversation
And whitespace cleaup while we are at it.
For now, we will base changes on static dependency on new backend module.
While we do not use `Options` in `init/1` function, it is possible, that those will be needed in close future; hence such interface.
To make shure `NewVersion` will match.
paratemer. Cleans up function call, and make algorithm easier to understand, since we can easily see how `Acc` is initialized.
`get_user_roster/2` seens quite useless, but since it is exported, I don't won't to removed it. I would like to keep changes in interface seperate from backend introduction itself.
This one is done merly to increase readability (my understanding) of program. But it shows nicely where and how data format in backedn leaks into out logic.
And again introduced wrapped return value, which have to be pattern match, which itself will fail as soon as possible.
Plain cut-paste.
Plain cut-pase. And as it turn out `odbc` already returns same scheme.
This should simplify logic of those funciton, and allow easier changes to case-logic
Plain cut-pase.
It introdusess some code-duplication, but quite readable in my opinion.
And minor bux fix, due to typo.
We expect only binaries to be handled.
Preserve logic of commit b255dc2
Updated code and commit to version that is ready to be merged in; |
Is this on its way to a title change (I mean the DO NOT MERGE YET)? ;) |
@mpmiszczyk ping :) Are you going to finish this? Or if this is finished, could you rebase it so travis can test it. |
Any news? |
end; | ||
|
||
_ -> | ||
{lists:map(fun item_to_xml/1, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lists:map(fun item_to_xml/1, ejabberd_hooks:run_fold(roster_get, To#jid.lserver, [], [US]))
is generic. can be extracted into a separate function.
It has been done in #359 |
DO NOT MERGE YET
This is one of the modules mentioned in issue #123. While extracting common backend I've found few issues that should/need to be addressed before finishing
short introduction and file description
Original code started with two roster modules;
mod_roster
using Mnesia as it's backend andmod_roster_odbc
which used odbc as its library. I've started with extracting all backend specific logic frommod_roster
to new modulemod_roster_mnesia
; and repeated same process formod_roster_odbc
and new modulemod_roster_odbc_back
; after which I was left with four roster files. Two backend implementations (which share same behaviour) and two logic modules, which should be identical, and merger into one. Now, the whole problem is fact that they are not.Since most of those differences should be considered bugs, and will list them all, and we should decide how to solve them (mostly it is question of choosing mnesia way or odbc way).
A missing hook handlerOdbc module subscribes and implements hook that Mnesia one does not.
While I could not find any code that would run this hook in Mongoose, the p1 roster implementation does have it, and it is run there from
ejabber_c2s
module.Odbc module additional exportsboth
item_to_xml/1
androster_version/2
are exported, just like in p1 code, but no one seems to use them. And mnesia module, while still having those functions (and using them internally) does not export them.-get_versioning_feature
xmlel childrensBoth versions ware introduced together with
#xmlel
record, which makes it hard to pin-point the newer one.-process_item_attrs
-For given roster we can update i's
jid
; which mnesia module does withJID
and odbc module does withLJID
, (created from different fields ofjid
record). In p1 versionLJID
is used.This seems like simple bug; and I would suggest sticking to
LJID
We can see similar situation in
process_item_attrs_ws
function, withJID
in mnesia andLJID
in odbc.-remove_user
-In mnesia this function can handle strings (as lists) while odbc and p1 does not. Such code causes no additional failures, which I would consider a bug, and remove this list handling guard.
-push_item
not_found version handlingWhile implementation in both modules does not look to similar, the only difference is fact that in mnesia in case of missing version, we will not add
<<"version">>
at all while in odbc it is possible to write as versin atomnot_found
. Mnesia version seem older, but it is the one p1 uses-process_item_els
handling of#roster.xs
'esNot sure what those are. Mnesia save all of those (if there are no groups) with code from 2002; while odbc cares only about groups, by logic added with whole module in 2012. p1 acts like mnesia but it is hard to say how old code is (updated in 2013, but before ?? )
get_roster_of
This was originally part of
process_item_set
; and there are two main issues.jid vs ljidAgain mnesia uses
JID
for new roster and if record found it changes from savedLJID
(since that what should be saved) toJID
.Odbc uses
LJID
for new roster, and without any sense updatesUSJ
,US
andLJID
(with values by which it was found.resetting name and groupsIn same place, if roster is found in database both module reset
name
andgroups
Roster than goes to
process_item_attrs
which can set new name (?so resetting it before might be obsolete). And toprocess_item_els
which adds (not repleace) groups; which makes this addition necessary, or removing them before a bug.-process_subscription
jid vs ljid againmnesia creates new roster [with
JID
](https://github.com/mpmiszczyk/MongooseIM/blob/feature/mod_roster_backend_rewrite/apps/ejabberd/src/mod_roster.erl#LAnd yes, this new_if_no_found behaviour will factored; but for now I wanted per-case reference for such differences.
-out_subscription
-Calls function with
[]
( which is""
) when it should be<<>>
or even<<"">>
like in p1.-foreach
vsflatmap
-This is tricky one, and it is possible, that I just don't understand something.
Mnesia uses
foreach
just like p1 while odbc usesflatmap
. So while first one will return list of as manyok
as elements was given; the second will return list withok
only for those elements that we ware able to transalte to jid. This does not make much difference.What I don't understand is use of return of this function. Since we always return some kind of list (empty | one_element | ... ), how only use of this function could try to pattern match on single
ok
odbc error handlingData saved in odbc have to be translated from raw to binary. It is a process that can fail in some why. Wright now I handle such failure silently here and here; and we should decide on something more sane. Either
optimize mnesiaOdbc stores roster in two tables; roster in one, and it's groups in second. This allows some optimization in calls like
roster_without_groups
andwrite_roster_subscription
. Since we introduce level of abstraction over storing#roster
record, we might introduce similar optimizations and keepgroups
list in separate mnesia table (without changing record itself).