couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kxepal <...@git.apache.org>
Subject [GitHub] couchdb-couch-epi pull request: 2796 improve performance of provid...
Date Wed, 02 Sep 2015 16:50:42 GMT
Github user kxepal commented on a diff in the pull request:

    https://github.com/apache/couchdb-couch-epi/pull/8#discussion_r38556013
  
    --- Diff: src/couch_epi_data_gen.erl ---
    @@ -174,27 +175,43 @@ module_name({Service, Key}) when is_list(Service) andalso is_list(Key)
->
     
     is_updated(Handle, Source, Data) ->
         Sig = couch_epi_util:hash(Data),
    -    try Handle:version(Source) of
    -        {error, {unknown, Source}} -> true;
    -        {error, Reason} -> throw(Reason);
    -        Sig -> false;
    -        _ -> true
    -    catch
    -        error:undef -> true;
    -        Class:Reason ->
    -            throw({Class, {Source, Reason}})
    -    end.
    -
    +    if_exists(Handle, version, 1, true, fun() ->
    +        try Handle:version(Source) of
    +            {error, {unknown, Source}} -> true;
    +            {error, Reason} -> throw(Reason);
    +            Sig -> false;
    +            _ -> true
    +        catch
    +            Class:Reason ->
    +                throw({Class, {Source, Reason}})
    +        end
    +    end).
    +
    +save(Handle, undefined, []) ->
    +    case current_data(Handle) of
    +        [] -> generate(Handle, []);
    +        _Else -> ok
    +    end;
     save(Handle, Source, Data) ->
    -    CurrentData = get_current_data(Handle),
    +    CurrentData = current_data(Handle),
         NewDefs = lists:keystore(Source, 1, CurrentData, {Source, Data}),
         generate(Handle, NewDefs).
     
    -get_current_data(Handle) ->
    -    try Handle:by_source()
    -    catch error:undef -> []
    -    end.
    +current_data(Handle, Subscriber) ->
    +    if_exists(Handle, by_source, 1, [], fun() ->
    +        Handle:by_source(Subscriber)
    +    end).
     
    +current_data(Handle) ->
    +    if_exists(Handle, by_source, 0, [], fun() ->
    +        Handle:by_source()
    +    end).
    +
    +if_exists(Handle, Func, Arity, Default, Fun) ->
    --- End diff --
    
    `maybe_call` sounds as better name for this and less confusing.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message