mirror of
https://github.com/wanderer-industries/wanderer
synced 2025-12-12 10:45:54 +00:00
chore: fixed character updates issue
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
defmodule WandererApp.CachedInfo do
|
defmodule WandererApp.CachedInfo do
|
||||||
require Logger
|
require Logger
|
||||||
|
|
||||||
|
alias WandererAppWeb.Helpers.APIUtils
|
||||||
|
|
||||||
def run(_arg) do
|
def run(_arg) do
|
||||||
:ok = cache_trig_systems()
|
:ok = cache_trig_systems()
|
||||||
end
|
end
|
||||||
@@ -37,6 +39,8 @@ defmodule WandererApp.CachedInfo do
|
|||||||
end
|
end
|
||||||
|
|
||||||
def get_system_static_info(solar_system_id) do
|
def get_system_static_info(solar_system_id) do
|
||||||
|
{:ok, solar_system_id} = APIUtils.parse_int(solar_system_id)
|
||||||
|
|
||||||
case Cachex.get(:system_static_info_cache, solar_system_id) do
|
case Cachex.get(:system_static_info_cache, solar_system_id) do
|
||||||
{:ok, nil} ->
|
{:ok, nil} ->
|
||||||
case WandererApp.Api.MapSolarSystem.read() do
|
case WandererApp.Api.MapSolarSystem.read() do
|
||||||
|
|||||||
@@ -505,9 +505,9 @@ defmodule WandererApp.Map.Server.SystemsImpl do
|
|||||||
:ok
|
:ok
|
||||||
|
|
||||||
_ ->
|
_ ->
|
||||||
{:ok, solar_system_info} =
|
|
||||||
WandererApp.CachedInfo.get_system_static_info(location.solar_system_id)
|
WandererApp.CachedInfo.get_system_static_info(location.solar_system_id)
|
||||||
|
|> case do
|
||||||
|
{:ok, solar_system_info} ->
|
||||||
# Use upsert instead of create - handles race conditions gracefully
|
# Use upsert instead of create - handles race conditions gracefully
|
||||||
WandererApp.MapSystemRepo.upsert(%{
|
WandererApp.MapSystemRepo.upsert(%{
|
||||||
map_id: map_id,
|
map_id: map_id,
|
||||||
@@ -589,6 +589,43 @@ defmodule WandererApp.Map.Server.SystemsImpl do
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
{:error, error}
|
||||||
|
end
|
||||||
|
|
||||||
|
{:error, error} = result ->
|
||||||
|
Logger.warning(
|
||||||
|
"[CharacterTracking] Failed to add system #{inspect(location.solar_system_id)} on map #{map_id}: #{inspect(error, pretty: true)}"
|
||||||
|
)
|
||||||
|
|
||||||
|
:telemetry.execute(
|
||||||
|
[:wanderer_app, :map, :system_addition, :error],
|
||||||
|
%{system_time: System.system_time()},
|
||||||
|
%{
|
||||||
|
map_id: map_id,
|
||||||
|
solar_system_id: location.solar_system_id,
|
||||||
|
error: error,
|
||||||
|
reason: :db_upsert_failed
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
result
|
||||||
|
|
||||||
|
error ->
|
||||||
|
Logger.warning(
|
||||||
|
"[CharacterTracking] Failed to add system #{inspect(location.solar_system_id)} on map #{map_id}: #{inspect(error, pretty: true)}"
|
||||||
|
)
|
||||||
|
|
||||||
|
:telemetry.execute(
|
||||||
|
[:wanderer_app, :map, :system_addition, :error],
|
||||||
|
%{system_time: System.system_time()},
|
||||||
|
%{
|
||||||
|
map_id: map_id,
|
||||||
|
solar_system_id: location.solar_system_id,
|
||||||
|
error: error,
|
||||||
|
reason: :db_upsert_failed_unexpected
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
{:error, error}
|
{:error, error}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -74,8 +74,10 @@ defmodule WandererAppWeb.Helpers.APIUtils do
|
|||||||
end
|
end
|
||||||
|
|
||||||
@spec parse_int(binary() | integer()) :: {:ok, integer()} | {:error, String.t()}
|
@spec parse_int(binary() | integer()) :: {:ok, integer()} | {:error, String.t()}
|
||||||
|
def parse_int(nil), do: {:ok, nil}
|
||||||
|
|
||||||
def parse_int(str) when is_binary(str) do
|
def parse_int(str) when is_binary(str) do
|
||||||
Logger.debug("Parsing integer from: #{inspect(str)}")
|
Logger.debug(fn -> "Parsing integer from: #{inspect(str)}" end)
|
||||||
|
|
||||||
case Integer.parse(str) do
|
case Integer.parse(str) do
|
||||||
{num, ""} -> {:ok, num}
|
{num, ""} -> {:ok, num}
|
||||||
|
|||||||
Reference in New Issue
Block a user