-module(pgl@internal@query_cache). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]). -define(FILEPATH, "src/pgl/internal/query_cache.gleam"). -export([lookup/2, insert/3, reset/1, delete/2, shutdown/1, start/1, supervised/1, new/0]). -export_type([query_cache/0, message/0]). -if(?OTP_RELEASE >= 27). -define(MODULEDOC(Str), -moduledoc(Str)). -define(DOC(Str), -doc(Str)). -else. -define(MODULEDOC(Str), -compile([])). -define(DOC(Str), -compile([])). -endif. ?MODULEDOC(false). -opaque query_cache() :: {query_cache, gleam@erlang@process:name(message())}. -type message() :: {lookup, gleam@erlang@process:subject({ok, list(integer())} | {error, nil}), binary()} | {insert, gleam@erlang@process:subject({ok, nil} | {error, nil}), binary(), list(integer())} | reset | {delete, binary()} | shutdown. -file("src/pgl/internal/query_cache.gleam", 56). ?DOC(false). -spec lookup(query_cache(), binary()) -> {ok, list(integer())} | {error, nil}. lookup(Query_cache, Query) -> _pipe = gleam@erlang@process:named_subject(erlang:element(2, Query_cache)), gleam@otp@actor:call( _pipe, 1000, fun(_capture) -> {lookup, _capture, Query} end ). -file("src/pgl/internal/query_cache.gleam", 61). ?DOC(false). -spec insert(query_cache(), binary(), list(integer())) -> {ok, nil} | {error, nil}. insert(Query_cache, Query, Oids) -> _pipe = gleam@erlang@process:named_subject(erlang:element(2, Query_cache)), gleam@otp@actor:call( _pipe, 1000, fun(_capture) -> {insert, _capture, Query, Oids} end ). -file("src/pgl/internal/query_cache.gleam", 70). ?DOC(false). -spec reset(query_cache()) -> nil. reset(Query_cache) -> _pipe = gleam@erlang@process:named_subject(erlang:element(2, Query_cache)), gleam@otp@actor:send(_pipe, reset). -file("src/pgl/internal/query_cache.gleam", 75). ?DOC(false). -spec delete(query_cache(), binary()) -> nil. delete(Query_cache, Query) -> _pipe = gleam@erlang@process:named_subject(erlang:element(2, Query_cache)), gleam@otp@actor:send(_pipe, {delete, Query}). -file("src/pgl/internal/query_cache.gleam", 80). ?DOC(false). -spec shutdown(query_cache()) -> nil. shutdown(Query_cache) -> _pipe = gleam@erlang@process:named_subject(erlang:element(2, Query_cache)), gleam@erlang@process:send(_pipe, shutdown). -file("src/pgl/internal/query_cache.gleam", 85). ?DOC(false). -spec handle_message(rasa@table:table(binary(), list(integer())), message()) -> gleam@otp@actor:next(rasa@table:table(binary(), list(integer())), message()). handle_message(Table, Msg) -> case Msg of {lookup, Client, Query} -> _pipe = rasa@table:lookup(Table, Query), gleam@otp@actor:send(Client, _pipe), gleam@otp@actor:continue(Table); {insert, Client@1, Query@1, Description} -> _pipe@1 = rasa@table:insert(Table, Query@1, Description), _pipe@2 = gleam@result:replace(_pipe@1, nil), gleam@otp@actor:send(Client@1, _pipe@2), gleam@otp@actor:continue(Table); reset -> _ = rasa@table:drop(Table), _pipe@3 = rasa@table:new(), _pipe@4 = rasa@table:with_access(_pipe@3, private), _pipe@5 = rasa@table:build(_pipe@4), gleam@otp@actor:continue(_pipe@5); {delete, Query@2} -> _ = rasa@table:delete(Table, Query@2), gleam@otp@actor:continue(Table); shutdown -> _ = rasa@table:drop(Table), gleam@otp@actor:stop() end. -file("src/pgl/internal/query_cache.gleam", 38). ?DOC(false). -spec start(query_cache()) -> {ok, gleam@otp@actor:started(nil)} | {error, gleam@otp@actor:start_error()}. start(Query_cache) -> _pipe@6 = gleam@otp@actor:new_with_initialiser( 1000, fun(Subj) -> Selector = begin _pipe = gleam_erlang_ffi:new_selector(), gleam@erlang@process:select(_pipe, Subj) end, _pipe@1 = rasa@table:new(), _pipe@2 = rasa@table:with_access(_pipe@1, private), _pipe@3 = rasa@table:build(_pipe@2), _pipe@4 = gleam@otp@actor:initialised(_pipe@3), _pipe@5 = gleam@otp@actor:selecting(_pipe@4, Selector), {ok, _pipe@5} end ), _pipe@7 = gleam@otp@actor:named(_pipe@6, erlang:element(2, Query_cache)), _pipe@8 = gleam@otp@actor:on_message(_pipe@7, fun handle_message/2), gleam@otp@actor:start(_pipe@8). -file("src/pgl/internal/query_cache.gleam", 31). ?DOC(false). -spec supervised(query_cache()) -> gleam@otp@supervision:child_specification(nil). supervised(Query_cache) -> _pipe = gleam@otp@supervision:worker(fun() -> start(Query_cache) end), gleam@otp@supervision:restart(_pipe, transient). -file("src/pgl/internal/query_cache.gleam", 25). ?DOC(false). -spec new() -> query_cache(). new() -> _pipe = <<"pgl_query_cache"/utf8>>, _pipe@1 = gleam_erlang_ffi:new_name(_pipe), {query_cache, _pipe@1}.