Skip to content

Instantly share code, notes, and snippets.

@gumayunov
Created May 13, 2010 04:39
Show Gist options
  • Save gumayunov/399500 to your computer and use it in GitHub Desktop.
Save gumayunov/399500 to your computer and use it in GitHub Desktop.
%% 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