Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions PortaCapena.OdooJsonRpcClient/OdooClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using System.Threading.Tasks;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using System.Collections.Concurrent;
using PortaCapena.OdooJsonRpcClient.Consts;
using PortaCapena.OdooJsonRpcClient.Extensions;
using PortaCapena.OdooJsonRpcClient.Models;
Expand All @@ -23,7 +24,7 @@ public sealed class OdooClient
private static HttpClient _client;
public OdooConfig Config { get; }

[ThreadStatic] private static int? _userUid;
private static readonly ConcurrentDictionary<string, int> _userUid = new ConcurrentDictionary<string, int>();

/// <summary>
/// Can be set to false, if server certificate shall not be validated.
Expand Down Expand Up @@ -298,8 +299,8 @@ public static async Task<OdooResult<bool>> DeleteRangeAsync(OdooConfig odooConfi

public async Task<OdooResult<int>> GetCurrentUserUidOrLoginAsync(CancellationToken cancellationToken = default)
{
if (_userUid.HasValue)
return await Task.FromResult(OdooResult<int>.SucceedResult(_userUid.Value));
if (_userUid.ContainsKey(Config.ApiUrl))
return await Task.FromResult(OdooResult<int>.SucceedResult(_userUid[Config.ApiUrl]));

return await LoginAsync(cancellationToken);
}
Expand All @@ -308,7 +309,7 @@ public async Task<OdooResult<int>> LoginAsync(CancellationToken cancellationToke
var result = await LoginAsync(Config, cancellationToken);

if (result.Succeed)
_userUid = result.Value;
_userUid[Config.ApiUrl] = result.Value;

return result;
}
Expand Down