feat(archive): month snapshots on the same node, drop extra-node and HTML /view.
Fixes EventHub/EventHubBack#76 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -184,6 +184,8 @@ create_event(Req) ->
|
||||
handler_utils:send_error(Req2, 404, <<"Calendar not found">>);
|
||||
{error, event_in_past} ->
|
||||
handler_utils:send_error(Req2, 400, <<"Event cannot be in the past">>);
|
||||
{error, archived} ->
|
||||
handler_utils:send_error(Req2, 409, <<"Month is archived">>);
|
||||
{error, {content_banned, _}} ->
|
||||
handler_utils:send_error(Req2, 400, <<"Content contains banned words">>);
|
||||
{error, _} ->
|
||||
@@ -201,6 +203,8 @@ create_event(Req) ->
|
||||
handler_utils:send_error(Req2, 404, <<"Calendar not found">>);
|
||||
{error, event_in_past} ->
|
||||
handler_utils:send_error(Req2, 400, <<"Event cannot be in the past">>);
|
||||
{error, archived} ->
|
||||
handler_utils:send_error(Req2, 409, <<"Month is archived">>);
|
||||
{error, {content_banned, _}} ->
|
||||
handler_utils:send_error(Req2, 400, <<"Content contains banned words">>);
|
||||
{error, _} ->
|
||||
@@ -239,7 +243,10 @@ list_events(Req) ->
|
||||
{FromStr, ToStr} ->
|
||||
FromDt = parse_datetime_binary(FromStr),
|
||||
ToDt = parse_datetime_binary(ToStr),
|
||||
expand_recurring_events(UserId, Events, FromDt, ToDt)
|
||||
HotJson = expand_recurring_events(UserId, Events, FromDt, ToDt),
|
||||
SnapJson = logic_month_archive:events_json_in_range(
|
||||
CalendarId, FromDt, ToDt),
|
||||
merge_event_json(HotJson, SnapJson)
|
||||
end,
|
||||
handler_utils:send_json(Req1, 200, Response);
|
||||
{error, access_denied} ->
|
||||
@@ -308,24 +315,36 @@ expand_recurring_events(UserId, Events, From, To) ->
|
||||
lists:flatmap(fun(Event) ->
|
||||
case Event#event.event_type of
|
||||
single ->
|
||||
case is_in_range(Event#event.start_time, From, To) of
|
||||
true -> [handler_utils:event_to_json(Event)];
|
||||
false -> []
|
||||
case logic_month_archive:month_is_closed(Event#event.start_time) of
|
||||
true -> [];
|
||||
false ->
|
||||
case is_in_range(Event#event.start_time, From, To) of
|
||||
true -> [handler_utils:event_to_json(Event)];
|
||||
false -> []
|
||||
end
|
||||
end;
|
||||
recurring ->
|
||||
case logic_event:get_occurrences(UserId, Event#event.id, To) of
|
||||
{ok, Occurrences} ->
|
||||
lists:filtermap(
|
||||
fun({virtual, Occ}) ->
|
||||
case is_in_range(Occ, From, To) of
|
||||
true -> {true, occurrence_to_json(Event, Occ)};
|
||||
false -> false
|
||||
case logic_month_archive:month_is_closed(Occ) of
|
||||
true -> false;
|
||||
false ->
|
||||
case is_in_range(Occ, From, To) of
|
||||
true -> {true, occurrence_to_json(Event, Occ)};
|
||||
false -> false
|
||||
end
|
||||
end;
|
||||
({materialized, Instance}) ->
|
||||
case is_in_range(Instance#event.start_time, From, To) of
|
||||
true -> {true, handler_utils:event_to_json(Instance)};
|
||||
false -> false
|
||||
end
|
||||
case logic_month_archive:month_is_closed(Instance#event.start_time) of
|
||||
true -> false;
|
||||
false ->
|
||||
case is_in_range(Instance#event.start_time, From, To) of
|
||||
true -> {true, handler_utils:event_to_json(Instance)};
|
||||
false -> false
|
||||
end
|
||||
end
|
||||
end, Occurrences);
|
||||
_ -> []
|
||||
end
|
||||
@@ -334,6 +353,16 @@ expand_recurring_events(UserId, Events, From, To) ->
|
||||
|
||||
is_in_range(Time, From, To) -> Time >= From andalso Time =< To.
|
||||
|
||||
merge_event_json(Hot, Snap) ->
|
||||
Ids = maps:from_list(
|
||||
[{maps:get(<<"id">>, M, maps:get(id, M, undefined)), true} || M <- Hot]),
|
||||
Extra = [M || M <- Snap,
|
||||
begin
|
||||
Id = maps:get(<<"id">>, M, maps:get(id, M, undefined)),
|
||||
Id =:= undefined orelse not maps:is_key(Id, Ids)
|
||||
end],
|
||||
Hot ++ Extra.
|
||||
|
||||
parse_datetime_binary(Str) ->
|
||||
{ok, Dt} = handler_utils:parse_datetime(Str),
|
||||
Dt.
|
||||
|
||||
Reference in New Issue
Block a user