You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@couchdb.apache.org by eiri <gi...@git.apache.org> on 2017/02/07 14:46:10 UTC
[GitHub] couchdb-couch-mrview pull request #65: Refactor mrview_index get
GitHub user eiri opened a pull request:
https://github.com/apache/couchdb-couch-mrview/pull/65
Refactor mrview_index get
This is a simple refactoring of mrview's `get/2` function that uses function's pattern matching instead of staircase case.
Arguably this makes code easier to read and more idiomatic.
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/cloudant/couchdb-couch-mrview refactor-mrview-index-get
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/couchdb-couch-mrview/pull/65.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #65
----
commit c079c1bb01197431b36fae11e8e287e9672bf9d9
Author: Eric Avdey <ei...@eiri.ca>
Date: 2017-02-07T14:39:46Z
Refactor mrview_index get
This is a simple refactoring of mrview's
get function that uses function's pattern
matching instead of staircase case.
Arguably this makes code easier to read
and more idiomatic.
----
---
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.
---
[GitHub] couchdb-couch-mrview pull request #65: Refactor mrview_index get
Posted by davisp <gi...@git.apache.org>.
Github user davisp commented on a diff in the pull request:
https://github.com/apache/couchdb-couch-mrview/pull/65#discussion_r100305494
--- Diff: src/couch_mrview_index.erl ---
@@ -23,84 +23,77 @@
-include_lib("couch_mrview/include/couch_mrview.hrl").
-get(Property, State) ->
- case Property of
- db_name ->
- State#mrst.db_name;
- idx_name ->
- State#mrst.idx_name;
- signature ->
- State#mrst.sig;
- update_seq ->
- State#mrst.update_seq;
- purge_seq ->
- State#mrst.purge_seq;
- update_options ->
- Opts = State#mrst.design_opts,
- IncDesign = couch_util:get_value(<<"include_design">>, Opts, false),
- LocalSeq = couch_util:get_value(<<"local_seq">>, Opts, false),
- SeqIndexed = couch_util:get_value(<<"seq_indexed">>, Opts, false),
- KeySeqIndexed = couch_util:get_value(<<"keyseq_indexed">>, Opts, false),
- if IncDesign -> [include_design]; true -> [] end
- ++ if LocalSeq -> [local_seq]; true -> [] end
- ++ if KeySeqIndexed -> [keyseq_indexed]; true -> [] end
- ++ if SeqIndexed -> [seq_indexed]; true -> [] end;
- fd ->
- State#mrst.fd;
- language ->
- State#mrst.language;
- views ->
- State#mrst.views;
- info ->
- #mrst{
- fd = Fd,
- sig = Sig,
- id_btree = IdBtree,
- log_btree = LogBtree,
- language = Lang,
- update_seq = UpdateSeq,
- purge_seq = PurgeSeq,
- views = Views,
- design_opts = Opts
- } = State,
- {ok, FileSize} = couch_file:bytes(Fd),
- {ok, ExternalSize} = couch_mrview_util:calculate_external_size(Views),
- LogBtSize = case LogBtree of
- nil ->
- 0;
- _ ->
- couch_btree:size(LogBtree)
- end,
- ActiveSize = couch_btree:size(IdBtree) + LogBtSize + ExternalSize,
-
- IncDesign = couch_util:get_value(<<"include_design">>, Opts, false),
- LocalSeq = couch_util:get_value(<<"local_seq">>, Opts, false),
- SeqIndexed = couch_util:get_value(<<"seq_indexed">>, Opts, false),
- KeySeqIndexed = couch_util:get_value(<<"keyseq_indexed">>, Opts, false),
- UpdateOptions =
- if IncDesign -> [<<"include_design">>]; true -> [] end
- ++ if LocalSeq -> [<<"local_seq">>]; true -> [] end
- ++ if KeySeqIndexed -> [<<"keyseq_indexed">>]; true -> [] end
- ++ if SeqIndexed -> [<<"seq_indexed">>]; true -> [] end,
-
-
- {ok, [
- {signature, list_to_binary(couch_index_util:hexsig(Sig))},
- {language, Lang},
- {disk_size, FileSize}, % legacy
- {data_size, ExternalSize}, % legacy
- {sizes, {[
- {file, FileSize},
- {active, ActiveSize},
- {external, ExternalSize}
- ]}},
- {update_seq, UpdateSeq},
- {purge_seq, PurgeSeq},
- {update_options, UpdateOptions}
- ]};
- Other ->
- throw({unknown_index_property, Other})
- end.
+get(db_name, #mrst{db_name = DbName}) ->
+ DbName;
+get(idx_name, #mrst{idx_name = IdxName}) ->
+ IdxName;
+get(signature, #mrst{sig = Signature}) ->
+ Signature;
+get(update_seq, #mrst{update_seq = UpdateSeq}) ->
+ UpdateSeq;
+get(purge_seq, #mrst{purge_seq = PurgeSeq}) ->
+ PurgeSeq;
+get(update_options, #mrst{design_opts = Opts}) ->
+ IncDesign = couch_util:get_value(<<"include_design">>, Opts, false),
+ LocalSeq = couch_util:get_value(<<"local_seq">>, Opts, false),
+ SeqIndexed = couch_util:get_value(<<"seq_indexed">>, Opts, false),
+ KeySeqIndexed = couch_util:get_value(<<"keyseq_indexed">>, Opts, false),
+ if IncDesign -> [include_design]; true -> [] end
+ ++ if LocalSeq -> [local_seq]; true -> [] end
+ ++ if KeySeqIndexed -> [keyseq_indexed]; true -> [] end
+ ++ if SeqIndexed -> [seq_indexed]; true -> [] end;
+get(fd, #mrst{fd = Fd}) ->
+ Fd;
+get(language, #mrst{language = Language}) ->
+ Language;
+get(views, #mrst{views = Views}) ->
+ Views;
+get(info, State) ->
+ #mrst{
+ fd = Fd,
+ sig = Sig,
+ id_btree = IdBtree,
+ log_btree = LogBtree,
+ language = Lang,
+ update_seq = UpdateSeq,
+ purge_seq = PurgeSeq,
+ views = Views,
+ design_opts = Opts
+ } = State,
+ {ok, FileSize} = couch_file:bytes(Fd),
+ {ok, ExternalSize} = couch_mrview_util:calculate_external_size(Views),
+ LogBtSize = case LogBtree of
+ nil ->
+ 0;
+ _ ->
+ couch_btree:size(LogBtree)
+ end,
+ ActiveSize = couch_btree:size(IdBtree) + LogBtSize + ExternalSize,
+
+ IncDesign = couch_util:get_value(<<"include_design">>, Opts, false),
+ LocalSeq = couch_util:get_value(<<"local_seq">>, Opts, false),
+ SeqIndexed = couch_util:get_value(<<"seq_indexed">>, Opts, false),
+ KeySeqIndexed = couch_util:get_value(<<"keyseq_indexed">>, Opts, false),
+
+ UpdateOptions0 = get(update_options, State),
+ UpdateOptions = [atom_to_binary(O, latin1) || O <- UpdateOptions0],
--- End diff --
LGTM
---
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.
---
[GitHub] couchdb-couch-mrview pull request #65: Refactor mrview_index get
Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:
https://github.com/apache/couchdb-couch-mrview/pull/65
---
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.
---
[GitHub] couchdb-couch-mrview pull request #65: Refactor mrview_index get
Posted by iilyak <gi...@git.apache.org>.
Github user iilyak commented on a diff in the pull request:
https://github.com/apache/couchdb-couch-mrview/pull/65#discussion_r99859905
--- Diff: src/couch_mrview_index.erl ---
@@ -23,84 +23,80 @@
-include_lib("couch_mrview/include/couch_mrview.hrl").
-get(Property, State) ->
- case Property of
- db_name ->
- State#mrst.db_name;
- idx_name ->
- State#mrst.idx_name;
- signature ->
- State#mrst.sig;
- update_seq ->
- State#mrst.update_seq;
- purge_seq ->
- State#mrst.purge_seq;
- update_options ->
- Opts = State#mrst.design_opts,
- IncDesign = couch_util:get_value(<<"include_design">>, Opts, false),
- LocalSeq = couch_util:get_value(<<"local_seq">>, Opts, false),
- SeqIndexed = couch_util:get_value(<<"seq_indexed">>, Opts, false),
- KeySeqIndexed = couch_util:get_value(<<"keyseq_indexed">>, Opts, false),
- if IncDesign -> [include_design]; true -> [] end
- ++ if LocalSeq -> [local_seq]; true -> [] end
- ++ if KeySeqIndexed -> [keyseq_indexed]; true -> [] end
- ++ if SeqIndexed -> [seq_indexed]; true -> [] end;
- fd ->
- State#mrst.fd;
- language ->
- State#mrst.language;
- views ->
- State#mrst.views;
- info ->
- #mrst{
- fd = Fd,
- sig = Sig,
- id_btree = IdBtree,
- log_btree = LogBtree,
- language = Lang,
- update_seq = UpdateSeq,
- purge_seq = PurgeSeq,
- views = Views,
- design_opts = Opts
- } = State,
- {ok, FileSize} = couch_file:bytes(Fd),
- {ok, ExternalSize} = couch_mrview_util:calculate_external_size(Views),
- LogBtSize = case LogBtree of
- nil ->
- 0;
- _ ->
- couch_btree:size(LogBtree)
- end,
- ActiveSize = couch_btree:size(IdBtree) + LogBtSize + ExternalSize,
-
- IncDesign = couch_util:get_value(<<"include_design">>, Opts, false),
- LocalSeq = couch_util:get_value(<<"local_seq">>, Opts, false),
- SeqIndexed = couch_util:get_value(<<"seq_indexed">>, Opts, false),
- KeySeqIndexed = couch_util:get_value(<<"keyseq_indexed">>, Opts, false),
- UpdateOptions =
- if IncDesign -> [<<"include_design">>]; true -> [] end
- ++ if LocalSeq -> [<<"local_seq">>]; true -> [] end
- ++ if KeySeqIndexed -> [<<"keyseq_indexed">>]; true -> [] end
- ++ if SeqIndexed -> [<<"seq_indexed">>]; true -> [] end,
-
-
- {ok, [
- {signature, list_to_binary(couch_index_util:hexsig(Sig))},
- {language, Lang},
- {disk_size, FileSize}, % legacy
- {data_size, ExternalSize}, % legacy
- {sizes, {[
- {file, FileSize},
- {active, ActiveSize},
- {external, ExternalSize}
- ]}},
- {update_seq, UpdateSeq},
- {purge_seq, PurgeSeq},
- {update_options, UpdateOptions}
- ]};
- Other ->
- throw({unknown_index_property, Other})
- end.
+get(db_name, #mrst{db_name = DbName}) ->
+ DbName;
+get(idx_name, #mrst{idx_name = IdxName}) ->
+ IdxName;
+get(signature, #mrst{sig = Signature}) ->
+ Signature;
+get(update_seq, #mrst{update_seq = UpdateSeq}) ->
+ UpdateSeq;
+get(purge_seq, #mrst{purge_seq = PurgeSeq}) ->
+ PurgeSeq;
+get(update_options, #mrst{design_opts = Opts}) ->
+ IncDesign = couch_util:get_value(<<"include_design">>, Opts, false),
+ LocalSeq = couch_util:get_value(<<"local_seq">>, Opts, false),
+ SeqIndexed = couch_util:get_value(<<"seq_indexed">>, Opts, false),
+ KeySeqIndexed = couch_util:get_value(<<"keyseq_indexed">>, Opts, false),
+ if IncDesign -> [include_design]; true -> [] end
+ ++ if LocalSeq -> [local_seq]; true -> [] end
+ ++ if KeySeqIndexed -> [keyseq_indexed]; true -> [] end
+ ++ if SeqIndexed -> [seq_indexed]; true -> [] end;
+get(fd, #mrst{fd = Fd}) ->
+ Fd;
+get(language, #mrst{language = Language}) ->
+ Language;
+get(views, #mrst{views = Views}) ->
+ Views;
+get(info, State) ->
+ #mrst{
+ fd = Fd,
+ sig = Sig,
+ id_btree = IdBtree,
+ log_btree = LogBtree,
+ language = Lang,
+ update_seq = UpdateSeq,
+ purge_seq = PurgeSeq,
+ views = Views,
+ design_opts = Opts
+ } = State,
+ {ok, FileSize} = couch_file:bytes(Fd),
+ {ok, ExternalSize} = couch_mrview_util:calculate_external_size(Views),
+ LogBtSize = case LogBtree of
+ nil ->
+ 0;
+ _ ->
+ couch_btree:size(LogBtree)
+ end,
+ ActiveSize = couch_btree:size(IdBtree) + LogBtSize + ExternalSize,
--- End diff --
Would this work?
```
UpdateOptions = get(update_options, State),
```
---
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.
---
[GitHub] couchdb-couch-mrview pull request #65: Refactor mrview_index get
Posted by eiri <gi...@git.apache.org>.
Github user eiri commented on a diff in the pull request:
https://github.com/apache/couchdb-couch-mrview/pull/65#discussion_r100131808
--- Diff: src/couch_mrview_index.erl ---
@@ -23,84 +23,77 @@
-include_lib("couch_mrview/include/couch_mrview.hrl").
-get(Property, State) ->
- case Property of
- db_name ->
- State#mrst.db_name;
- idx_name ->
- State#mrst.idx_name;
- signature ->
- State#mrst.sig;
- update_seq ->
- State#mrst.update_seq;
- purge_seq ->
- State#mrst.purge_seq;
- update_options ->
- Opts = State#mrst.design_opts,
- IncDesign = couch_util:get_value(<<"include_design">>, Opts, false),
- LocalSeq = couch_util:get_value(<<"local_seq">>, Opts, false),
- SeqIndexed = couch_util:get_value(<<"seq_indexed">>, Opts, false),
- KeySeqIndexed = couch_util:get_value(<<"keyseq_indexed">>, Opts, false),
- if IncDesign -> [include_design]; true -> [] end
- ++ if LocalSeq -> [local_seq]; true -> [] end
- ++ if KeySeqIndexed -> [keyseq_indexed]; true -> [] end
- ++ if SeqIndexed -> [seq_indexed]; true -> [] end;
- fd ->
- State#mrst.fd;
- language ->
- State#mrst.language;
- views ->
- State#mrst.views;
- info ->
- #mrst{
- fd = Fd,
- sig = Sig,
- id_btree = IdBtree,
- log_btree = LogBtree,
- language = Lang,
- update_seq = UpdateSeq,
- purge_seq = PurgeSeq,
- views = Views,
- design_opts = Opts
- } = State,
- {ok, FileSize} = couch_file:bytes(Fd),
- {ok, ExternalSize} = couch_mrview_util:calculate_external_size(Views),
- LogBtSize = case LogBtree of
- nil ->
- 0;
- _ ->
- couch_btree:size(LogBtree)
- end,
- ActiveSize = couch_btree:size(IdBtree) + LogBtSize + ExternalSize,
-
- IncDesign = couch_util:get_value(<<"include_design">>, Opts, false),
- LocalSeq = couch_util:get_value(<<"local_seq">>, Opts, false),
- SeqIndexed = couch_util:get_value(<<"seq_indexed">>, Opts, false),
- KeySeqIndexed = couch_util:get_value(<<"keyseq_indexed">>, Opts, false),
- UpdateOptions =
- if IncDesign -> [<<"include_design">>]; true -> [] end
- ++ if LocalSeq -> [<<"local_seq">>]; true -> [] end
- ++ if KeySeqIndexed -> [<<"keyseq_indexed">>]; true -> [] end
- ++ if SeqIndexed -> [<<"seq_indexed">>]; true -> [] end,
-
-
- {ok, [
- {signature, list_to_binary(couch_index_util:hexsig(Sig))},
- {language, Lang},
- {disk_size, FileSize}, % legacy
- {data_size, ExternalSize}, % legacy
- {sizes, {[
- {file, FileSize},
- {active, ActiveSize},
- {external, ExternalSize}
- ]}},
- {update_seq, UpdateSeq},
- {purge_seq, PurgeSeq},
- {update_options, UpdateOptions}
- ]};
- Other ->
- throw({unknown_index_property, Other})
- end.
+get(db_name, #mrst{db_name = DbName}) ->
+ DbName;
+get(idx_name, #mrst{idx_name = IdxName}) ->
+ IdxName;
+get(signature, #mrst{sig = Signature}) ->
+ Signature;
+get(update_seq, #mrst{update_seq = UpdateSeq}) ->
+ UpdateSeq;
+get(purge_seq, #mrst{purge_seq = PurgeSeq}) ->
+ PurgeSeq;
+get(update_options, #mrst{design_opts = Opts}) ->
+ IncDesign = couch_util:get_value(<<"include_design">>, Opts, false),
+ LocalSeq = couch_util:get_value(<<"local_seq">>, Opts, false),
+ SeqIndexed = couch_util:get_value(<<"seq_indexed">>, Opts, false),
+ KeySeqIndexed = couch_util:get_value(<<"keyseq_indexed">>, Opts, false),
+ if IncDesign -> [include_design]; true -> [] end
+ ++ if LocalSeq -> [local_seq]; true -> [] end
+ ++ if KeySeqIndexed -> [keyseq_indexed]; true -> [] end
+ ++ if SeqIndexed -> [seq_indexed]; true -> [] end;
+get(fd, #mrst{fd = Fd}) ->
+ Fd;
+get(language, #mrst{language = Language}) ->
+ Language;
+get(views, #mrst{views = Views}) ->
+ Views;
+get(info, State) ->
+ #mrst{
+ fd = Fd,
+ sig = Sig,
+ id_btree = IdBtree,
+ log_btree = LogBtree,
+ language = Lang,
+ update_seq = UpdateSeq,
+ purge_seq = PurgeSeq,
+ views = Views,
+ design_opts = Opts
+ } = State,
+ {ok, FileSize} = couch_file:bytes(Fd),
+ {ok, ExternalSize} = couch_mrview_util:calculate_external_size(Views),
+ LogBtSize = case LogBtree of
+ nil ->
+ 0;
+ _ ->
+ couch_btree:size(LogBtree)
+ end,
+ ActiveSize = couch_btree:size(IdBtree) + LogBtSize + ExternalSize,
+
+ IncDesign = couch_util:get_value(<<"include_design">>, Opts, false),
+ LocalSeq = couch_util:get_value(<<"local_seq">>, Opts, false),
+ SeqIndexed = couch_util:get_value(<<"seq_indexed">>, Opts, false),
+ KeySeqIndexed = couch_util:get_value(<<"keyseq_indexed">>, Opts, false),
+
+ UpdateOptions0 = get(update_options, State),
+ UpdateOptions = [atom_to_binary(O, latin1) || O <- UpdateOptions0],
--- End diff --
@iilyak something like this?
---
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.
---
[GitHub] couchdb-couch-mrview issue #65: Refactor mrview_index get
Posted by davisp <gi...@git.apache.org>.
Github user davisp commented on the issue:
https://github.com/apache/couchdb-couch-mrview/pull/65
I'll second re-using `get(update_options, State)` since those are prime suspects for being typoed if we ever change them.
Six-year-ago-me re-apologizes for couch_mrview.
---
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.
---
[GitHub] couchdb-couch-mrview pull request #65: Refactor mrview_index get
Posted by davisp <gi...@git.apache.org>.
Github user davisp commented on a diff in the pull request:
https://github.com/apache/couchdb-couch-mrview/pull/65#discussion_r99875440
--- Diff: src/couch_mrview_index.erl ---
@@ -23,84 +23,80 @@
-include_lib("couch_mrview/include/couch_mrview.hrl").
-get(Property, State) ->
- case Property of
- db_name ->
- State#mrst.db_name;
- idx_name ->
- State#mrst.idx_name;
- signature ->
- State#mrst.sig;
- update_seq ->
- State#mrst.update_seq;
- purge_seq ->
- State#mrst.purge_seq;
- update_options ->
- Opts = State#mrst.design_opts,
- IncDesign = couch_util:get_value(<<"include_design">>, Opts, false),
- LocalSeq = couch_util:get_value(<<"local_seq">>, Opts, false),
- SeqIndexed = couch_util:get_value(<<"seq_indexed">>, Opts, false),
- KeySeqIndexed = couch_util:get_value(<<"keyseq_indexed">>, Opts, false),
- if IncDesign -> [include_design]; true -> [] end
- ++ if LocalSeq -> [local_seq]; true -> [] end
- ++ if KeySeqIndexed -> [keyseq_indexed]; true -> [] end
- ++ if SeqIndexed -> [seq_indexed]; true -> [] end;
- fd ->
- State#mrst.fd;
- language ->
- State#mrst.language;
- views ->
- State#mrst.views;
- info ->
- #mrst{
- fd = Fd,
- sig = Sig,
- id_btree = IdBtree,
- log_btree = LogBtree,
- language = Lang,
- update_seq = UpdateSeq,
- purge_seq = PurgeSeq,
- views = Views,
- design_opts = Opts
- } = State,
- {ok, FileSize} = couch_file:bytes(Fd),
- {ok, ExternalSize} = couch_mrview_util:calculate_external_size(Views),
- LogBtSize = case LogBtree of
- nil ->
- 0;
- _ ->
- couch_btree:size(LogBtree)
- end,
- ActiveSize = couch_btree:size(IdBtree) + LogBtSize + ExternalSize,
-
- IncDesign = couch_util:get_value(<<"include_design">>, Opts, false),
- LocalSeq = couch_util:get_value(<<"local_seq">>, Opts, false),
- SeqIndexed = couch_util:get_value(<<"seq_indexed">>, Opts, false),
- KeySeqIndexed = couch_util:get_value(<<"keyseq_indexed">>, Opts, false),
- UpdateOptions =
- if IncDesign -> [<<"include_design">>]; true -> [] end
- ++ if LocalSeq -> [<<"local_seq">>]; true -> [] end
- ++ if KeySeqIndexed -> [<<"keyseq_indexed">>]; true -> [] end
- ++ if SeqIndexed -> [<<"seq_indexed">>]; true -> [] end,
-
-
- {ok, [
- {signature, list_to_binary(couch_index_util:hexsig(Sig))},
- {language, Lang},
- {disk_size, FileSize}, % legacy
- {data_size, ExternalSize}, % legacy
- {sizes, {[
- {file, FileSize},
- {active, ActiveSize},
- {external, ExternalSize}
- ]}},
- {update_seq, UpdateSeq},
- {purge_seq, PurgeSeq},
- {update_options, UpdateOptions}
- ]};
- Other ->
- throw({unknown_index_property, Other})
- end.
+get(db_name, #mrst{db_name = DbName}) ->
+ DbName;
+get(idx_name, #mrst{idx_name = IdxName}) ->
+ IdxName;
+get(signature, #mrst{sig = Signature}) ->
+ Signature;
+get(update_seq, #mrst{update_seq = UpdateSeq}) ->
+ UpdateSeq;
+get(purge_seq, #mrst{purge_seq = PurgeSeq}) ->
+ PurgeSeq;
+get(update_options, #mrst{design_opts = Opts}) ->
+ IncDesign = couch_util:get_value(<<"include_design">>, Opts, false),
+ LocalSeq = couch_util:get_value(<<"local_seq">>, Opts, false),
+ SeqIndexed = couch_util:get_value(<<"seq_indexed">>, Opts, false),
+ KeySeqIndexed = couch_util:get_value(<<"keyseq_indexed">>, Opts, false),
+ if IncDesign -> [include_design]; true -> [] end
+ ++ if LocalSeq -> [local_seq]; true -> [] end
+ ++ if KeySeqIndexed -> [keyseq_indexed]; true -> [] end
+ ++ if SeqIndexed -> [seq_indexed]; true -> [] end;
+get(fd, #mrst{fd = Fd}) ->
+ Fd;
+get(language, #mrst{language = Language}) ->
+ Language;
+get(views, #mrst{views = Views}) ->
+ Views;
+get(info, State) ->
+ #mrst{
+ fd = Fd,
+ sig = Sig,
+ id_btree = IdBtree,
+ log_btree = LogBtree,
+ language = Lang,
+ update_seq = UpdateSeq,
+ purge_seq = PurgeSeq,
+ views = Views,
+ design_opts = Opts
+ } = State,
+ {ok, FileSize} = couch_file:bytes(Fd),
+ {ok, ExternalSize} = couch_mrview_util:calculate_external_size(Views),
+ LogBtSize = case LogBtree of
+ nil ->
+ 0;
+ _ ->
+ couch_btree:size(LogBtree)
+ end,
+ ActiveSize = couch_btree:size(IdBtree) + LogBtSize + ExternalSize,
--- End diff --
Pretty sure this was meant for a few lines down, but we could do that and then just run a map to turn the atoms into binaries.
---
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.
---
[GitHub] couchdb-couch-mrview issue #65: Refactor mrview_index get
Posted by davisp <gi...@git.apache.org>.
Github user davisp commented on the issue:
https://github.com/apache/couchdb-couch-mrview/pull/65
Also, +1 after the slight tweak.
---
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.
---
[GitHub] couchdb-couch-mrview pull request #65: Refactor mrview_index get
Posted by eiri <gi...@git.apache.org>.
Github user eiri commented on a diff in the pull request:
https://github.com/apache/couchdb-couch-mrview/pull/65#discussion_r99881145
--- Diff: src/couch_mrview_index.erl ---
@@ -23,84 +23,80 @@
-include_lib("couch_mrview/include/couch_mrview.hrl").
-get(Property, State) ->
- case Property of
- db_name ->
- State#mrst.db_name;
- idx_name ->
- State#mrst.idx_name;
- signature ->
- State#mrst.sig;
- update_seq ->
- State#mrst.update_seq;
- purge_seq ->
- State#mrst.purge_seq;
- update_options ->
- Opts = State#mrst.design_opts,
- IncDesign = couch_util:get_value(<<"include_design">>, Opts, false),
- LocalSeq = couch_util:get_value(<<"local_seq">>, Opts, false),
- SeqIndexed = couch_util:get_value(<<"seq_indexed">>, Opts, false),
- KeySeqIndexed = couch_util:get_value(<<"keyseq_indexed">>, Opts, false),
- if IncDesign -> [include_design]; true -> [] end
- ++ if LocalSeq -> [local_seq]; true -> [] end
- ++ if KeySeqIndexed -> [keyseq_indexed]; true -> [] end
- ++ if SeqIndexed -> [seq_indexed]; true -> [] end;
- fd ->
- State#mrst.fd;
- language ->
- State#mrst.language;
- views ->
- State#mrst.views;
- info ->
- #mrst{
- fd = Fd,
- sig = Sig,
- id_btree = IdBtree,
- log_btree = LogBtree,
- language = Lang,
- update_seq = UpdateSeq,
- purge_seq = PurgeSeq,
- views = Views,
- design_opts = Opts
- } = State,
- {ok, FileSize} = couch_file:bytes(Fd),
- {ok, ExternalSize} = couch_mrview_util:calculate_external_size(Views),
- LogBtSize = case LogBtree of
- nil ->
- 0;
- _ ->
- couch_btree:size(LogBtree)
- end,
- ActiveSize = couch_btree:size(IdBtree) + LogBtSize + ExternalSize,
-
- IncDesign = couch_util:get_value(<<"include_design">>, Opts, false),
- LocalSeq = couch_util:get_value(<<"local_seq">>, Opts, false),
- SeqIndexed = couch_util:get_value(<<"seq_indexed">>, Opts, false),
- KeySeqIndexed = couch_util:get_value(<<"keyseq_indexed">>, Opts, false),
- UpdateOptions =
- if IncDesign -> [<<"include_design">>]; true -> [] end
- ++ if LocalSeq -> [<<"local_seq">>]; true -> [] end
- ++ if KeySeqIndexed -> [<<"keyseq_indexed">>]; true -> [] end
- ++ if SeqIndexed -> [<<"seq_indexed">>]; true -> [] end,
-
-
- {ok, [
- {signature, list_to_binary(couch_index_util:hexsig(Sig))},
- {language, Lang},
- {disk_size, FileSize}, % legacy
- {data_size, ExternalSize}, % legacy
- {sizes, {[
- {file, FileSize},
- {active, ActiveSize},
- {external, ExternalSize}
- ]}},
- {update_seq, UpdateSeq},
- {purge_seq, PurgeSeq},
- {update_options, UpdateOptions}
- ]};
- Other ->
- throw({unknown_index_property, Other})
- end.
+get(db_name, #mrst{db_name = DbName}) ->
+ DbName;
+get(idx_name, #mrst{idx_name = IdxName}) ->
+ IdxName;
+get(signature, #mrst{sig = Signature}) ->
+ Signature;
+get(update_seq, #mrst{update_seq = UpdateSeq}) ->
+ UpdateSeq;
+get(purge_seq, #mrst{purge_seq = PurgeSeq}) ->
+ PurgeSeq;
+get(update_options, #mrst{design_opts = Opts}) ->
+ IncDesign = couch_util:get_value(<<"include_design">>, Opts, false),
+ LocalSeq = couch_util:get_value(<<"local_seq">>, Opts, false),
+ SeqIndexed = couch_util:get_value(<<"seq_indexed">>, Opts, false),
+ KeySeqIndexed = couch_util:get_value(<<"keyseq_indexed">>, Opts, false),
+ if IncDesign -> [include_design]; true -> [] end
+ ++ if LocalSeq -> [local_seq]; true -> [] end
+ ++ if KeySeqIndexed -> [keyseq_indexed]; true -> [] end
+ ++ if SeqIndexed -> [seq_indexed]; true -> [] end;
+get(fd, #mrst{fd = Fd}) ->
+ Fd;
+get(language, #mrst{language = Language}) ->
+ Language;
+get(views, #mrst{views = Views}) ->
+ Views;
+get(info, State) ->
+ #mrst{
+ fd = Fd,
+ sig = Sig,
+ id_btree = IdBtree,
+ log_btree = LogBtree,
+ language = Lang,
+ update_seq = UpdateSeq,
+ purge_seq = PurgeSeq,
+ views = Views,
+ design_opts = Opts
+ } = State,
+ {ok, FileSize} = couch_file:bytes(Fd),
+ {ok, ExternalSize} = couch_mrview_util:calculate_external_size(Views),
+ LogBtSize = case LogBtree of
+ nil ->
+ 0;
+ _ ->
+ couch_btree:size(LogBtree)
+ end,
+ ActiveSize = couch_btree:size(IdBtree) + LogBtSize + ExternalSize,
--- End diff --
@iilyak yes, sure, good Idea. I just didn't want to complicate review more than necessary by refactoring and changing code at the same time. I'll do the tweak.
---
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.
---