Created
May 13, 2010 04:39
-
-
Save gumayunov/399500 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%% index comments | |
handle(HD, get, {comments}, Req) -> | |
[CommentableId, CommentableType] = commentable_params(Req), | |
Result = case ut:all_defined([CommentableType, CommentableId]) of | |
true -> | |
Key = {CommentableType, CommentableId}, | |
case cache:get(commentable_cache, Key) of | |
undefined -> | |
Comments = select_comments(person_write, CommentableType, CommentableId), | |
UserIDs = lists:map(fun(Comment)-> proplists:get_value(user_id, Comment) end, Comments), | |
[Uinfoes, Statuses] = ut:multi_call([ | |
fun() -> select_uinfoes_by_ids(person_read, UserIDs) end, | |
fun() -> select_statuses_by_uids(onliners_write, UserIDs) end | |
]), | |
Result = {[ | |
{comments, ut:jmap(Comments)}, | |
{uinfoes, ut:jmap(Uinfoes)}, | |
{statuses, {Statuses}} | |
]}, | |
cache:set(commentable_cache, Key, ejson:encode(Result)), | |
{ok, Result}; | |
CachedJson -> | |
{ok, ejson:decode(CachedJson)} | |
_ -> | |
error_400 | |
end, | |
response(Result); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment