<commit_before>:- module(bc_mail_queue, [
    bc_mail_enqueue_text/4, % +Text, +From, +Subject, +To
    bc_mail_queue_wipe/0,
    bc_mail_queue_size/1,   % -Size
    bc_mail_set_behavior/1  % +Behavior
]).

:- use_module(library(error)).
:- use_module(library(debug)).
:- use_module(library(docstore)).

:- use_module(bc_mail).

% Queue behavior: ignore, retain, send.
% Production value is send.

:- dynamic(behavior/1).
:- dynamic(queue/5).

% Default is used for testing.

:- assertz(behavior(retain)).

bc_mail_set_behavior(Behavior):-
    must_be(oneof([retain, send, ignore]), Behavior),
    retractall(behavior(_)),
    assertz(behavior(Behavior)).

bc_mail_enqueue_text(Text, From, Subject, To):-
    must_be(atomic, Text),
    must_be(atomic, From),
    must_be(atomic, Subject),
    must_be(atomic, To),
    (   behavior(ignore)
    ->  true
    ;   ds_uuid(Uuid),
        assertz(queue(Uuid, Text, From, Subject, To)),
        debug(bc_mail, 'queued mail to ~w', [To])).

bc_mail_queue_wipe:-
    retractall(queue(_, _, _, _, _)),
    debug(bc_mail, 'wiping mail queue', []).

bc_mail_queue_size(Size):-
    findall(_, queue(_, _, _, _, _), Mails),
    length(Mails, Size).

% Sleep time setting for the
% mail queue thread.

queue_thread_sleep(10).

start_mail_thread:-
    debug(bc_mail, 'started queue thread', []),
    queue_thread_sleep(Sleep),
    sleep(Sleep),
    queue_loop.

% Tail-call optimized loop.<commit_msg>Decrease mail queue time to 1s<commit_after>:- module(bc_mail_queue, [
    bc_mail_enqueue_text/4, % +Text, +From, +Subject, +To
    bc_mail_queue_wipe/0,
    bc_mail_queue_size/1,   % -Size
    bc_mail_set_behavior/1  % +Behavior
]).

:- use_module(library(error)).
:- use_module(library(debug)).
:- use_module(library(docstore)).

:- use_module(bc_mail).

% Queue behavior: ignore, retain, send.
% Production value is send.

:- dynamic(behavior/1).
:- dynamic(queue/5).

% Default is used for testing.

:- assertz(behavior(retain)).

bc_mail_set_behavior(Behavior):-
    must_be(oneof([retain, send, ignore]), Behavior),
    retractall(behavior(_)),
    assertz(behavior(Behavior)).

bc_mail_enqueue_text(Text, From, Subject, To):-
    must_be(atomic, Text),
    must_be(atomic, From),
    must_be(atomic, Subject),
    must_be(atomic, To),
    (   behavior(ignore)
    ->  true
    ;   ds_uuid(Uuid),
        assertz(queue(Uuid, Text, From, Subject, To)),
        debug(bc_mail, 'queued mail to ~w', [To])).

bc_mail_queue_wipe:-
    retractall(queue(_, _, _, _, _)),
    debug(bc_mail, 'wiping mail queue', []).

bc_mail_queue_size(Size):-
    findall(_, queue(_, _, _, _, _), Mails),
    length(Mails, Size).

% Sleep time setting for the
% mail queue thread.

queue_thread_sleep(1).

start_mail_thread:-
    debug(bc_mail, 'started queue thread', []),
    queue_thread_sleep(Sleep),
    sleep(Sleep),
    queue_loop.

% Tail-call optimized loop.
{'fraction_non_alphanumeric': 0.15661815661815662, 'fraction_numerical': 0.005544005544005544, 'mean_word_length': 3.8439597315436242, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '5186454', 'n_tokens_mistral': 1072, 'n_tokens_neox': 1047, 'n_words': 200}