<commit_before>%%%-------------------------------------------------------------------
%%% @author benoitc
%%% @copyright (C) 2017, <COMPANY>
%%% @doc
%%%
%%% @end
%%% Created : 08. Mar 2017 22:16
%%%-------------------------------------------------------------------
-module(barrel_write_batch).
-author("benoitc").

%% API
-export([
  new/1,
  put/3,
  post/3,
  delete/3,
  put_rev/4,
  to_buckets/1,
  from_list/2,
  is_batch/1
]).

-include_lib("barrel_common/include/barrel_common.hrl").

-type batch() :: tuple().
-type batch_op() :: {put, Doc :: barrel_local:doc(), Rev :: barrel_local:revid()} |
                    {post, Doc :: barrel_local:doc(), IsUpsert :: boolean()} |
                    {delete, DocId :: barrel_local:docid(), Rev :: barrel_local:revid()} |
                    {post, Doc :: barrel_local:doc(), History :: list(), Deleted :: boolean()} |
                    map().

-export_type([
  batch/0,
  batch_op/0
]).

-spec new(Async) -> Batch when
  Async :: boolean(),
  Batch :: batch().
new(Async) ->
  {#{}, self(), make_ref(), Async, 0}.

-spec put(Obj, Rev, BatchIn) -> BatchOut when
  Obj :: barrel_local:doc(),
  Rev :: barrel_local:revid(),
  BatchIn :: batch(),
  BatchOut :: batch().
put(Obj, Rev, Batch) ->
  ok = validate_docid(Obj),
  Doc = barrel_doc:make_doc(Obj, [Rev], false),
  Req = make_req(Batch),
  Op = make_op(Doc, Req, false, false, false),
  update_batch(Doc#doc.id, Op, Batch).

-spec post(Obj, IsUpsert, BatchIn) -> BatchOut when
  Obj :: barrel_local:doc(),
  IsUpsert :: boolean(),
  BatchIn :: batch(),<commit_msg>fix spec<commit_after>%%%-------------------------------------------------------------------
%%% @author benoitc
%%% @copyright (C) 2017, <COMPANY>
%%% @doc
%%%
%%% @end
%%% Created : 08. Mar 2017 22:16
%%%-------------------------------------------------------------------
-module(barrel_write_batch).
-author("benoitc").

%% API
-export([
  new/1,
  put/3,
  post/3,
  delete/3,
  put_rev/4,
  to_buckets/1,
  from_list/2,
  is_batch/1
]).

-include_lib("barrel_common/include/barrel_common.hrl").

-type batch() :: tuple().
-type batch_op() :: {put, Doc :: barrel_local:doc(), Rev :: barrel_local:revid()} |
                    {post, Doc :: barrel_local:doc(), IsUpsert :: boolean()} |
                    {delete, DocId :: barrel_local:docid(), Rev :: barrel_local:revid()} |
                    {put_rev, Doc :: barrel_local:doc(), History :: list(), Deleted :: boolean()} |
                    map().

-export_type([
  batch/0,
  batch_op/0
]).

-spec new(Async) -> Batch when
  Async :: boolean(),
  Batch :: batch().
new(Async) ->
  {#{}, self(), make_ref(), Async, 0}.

-spec put(Obj, Rev, BatchIn) -> BatchOut when
  Obj :: barrel_local:doc(),
  Rev :: barrel_local:revid(),
  BatchIn :: batch(),
  BatchOut :: batch().
put(Obj, Rev, Batch) ->
  ok = validate_docid(Obj),
  Doc = barrel_doc:make_doc(Obj, [Rev], false),
  Req = make_req(Batch),
  Op = make_op(Doc, Req, false, false, false),
  update_batch(Doc#doc.id, Op, Batch).

-spec post(Obj, IsUpsert, BatchIn) -> BatchOut when
  Obj :: barrel_local:doc(),
  IsUpsert :: boolean(),
  BatchIn :: batch(),
{'fraction_non_alphanumeric': 0.27116486314449395, 'fraction_numerical': 0.015913430935709738, 'mean_word_length': 2.3154008438818567, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3423787', 'n_tokens_mistral': 1126, 'n_tokens_neox': 1079, 'n_words': 234}