Class WorldPortalStateService
Persists portals opened for the whole world: one row per (scene, portal index).
public sealed class WorldPortalStateService : BaseService<WorldPortalStateEntity>, IWorldPortalStateService, IFetchCollectionByKeyAction<string, WorldPortalStateData>
- Inheritance
-
WorldPortalStateService
- Implements
- Inherited Members
Remarks
The merge is done in SQL so two scene servers opening the same portal at once converge:
permanent ORs and active_until takes GREATEST, never the newer write.
Constructors
WorldPortalStateService(INpgsqlDbContextFactory)
public WorldPortalStateService(INpgsqlDbContextFactory dbContextFactory)
Parameters
dbContextFactoryINpgsqlDbContextFactory
Methods
FetchAsync(string, CancellationToken)
Fetches a collection of items for the given key.
public Task<DatabaseResult<IReadOnlyList<WorldPortalStateData>>> FetchAsync(string sceneName, CancellationToken cancellationToken = default)
Parameters
sceneNamestringcancellationTokenCancellationTokenToken to cancel the operation.
Returns
MergeAsync(IEnumerable<WorldPortalStateData>, CancellationToken)
Merges openings into the stored rows: permanent ORs and active_until takes
the later moment. Creates rows that do not exist yet.
public Task<DatabaseResult> MergeAsync(IEnumerable<WorldPortalStateData> states, CancellationToken cancellationToken = default)
Parameters
statesIEnumerable<WorldPortalStateData>The openings to merge.
cancellationTokenCancellationTokenToken to cancel the operation.
Returns
- Task<DatabaseResult>
Success, or the failure that stopped the whole batch.
Remarks
Idempotent: a retry after an ambiguous failure changes nothing.