mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-10 09:53:48 +00:00
refactor: create transaction system and apply to adding entry (#1620)
* refactor: create transaction system and apply to adding entry * refactor: migrate edit mutations to transaction * refactor: migrate delete mutation to transaction * refactor: migrate reorder mutation to transaction * refactor: migrate apply delay to transaction * refactor: migrate swapEvents to transaction * refactor: migrate clone to transaction * refactor: migrate group/ungroup transactions * refactor: simplify mutations * refactor: migrate getters * chore: add tests to processRundown()
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { MessageState, OffsetMode, OntimeEvent, SimpleDirection, SimplePlayback } from 'ontime-types';
|
||||
import { MessageState, OffsetMode, OntimeEvent, PatchWithId, SimpleDirection, SimplePlayback } from 'ontime-types';
|
||||
import { MILLIS_PER_HOUR } from 'ontime-utils';
|
||||
|
||||
import { DeepPartial } from 'ts-essentials';
|
||||
@@ -11,13 +11,14 @@ import { runtimeService } from '../services/runtime-service/RuntimeService.js';
|
||||
import { eventStore } from '../stores/EventStore.js';
|
||||
import * as assert from '../utils/assert.js';
|
||||
import { isEmptyObject } from '../utils/parserUtils.js';
|
||||
import { parseProperty, updateEvent } from './integration.utils.js';
|
||||
import { parseProperty } from './integration.utils.js';
|
||||
import { socket } from '../adapters/WebsocketAdapter.js';
|
||||
import { throttle } from '../utils/throttle.js';
|
||||
import { willCauseRegeneration } from '../services/rundown-service/rundownCache.utils.js';
|
||||
import { coerceEnum } from '../utils/coerceType.js';
|
||||
import { editEntry } from '../api-data/rundown/rundown.service.js';
|
||||
import { willCauseRegeneration } from '../api-data/rundown/rundown.utils.js';
|
||||
|
||||
const throttledUpdateEvent = throttle(updateEvent, 20);
|
||||
const throttledEditEvent = throttle(editEntry, 20);
|
||||
let lastRequest: Date | null = null;
|
||||
|
||||
export function dispatchFromAdapter(type: string, payload: unknown, _source?: 'osc' | 'ws' | 'http') {
|
||||
@@ -56,7 +57,7 @@ const actionHandlers: Record<string, ActionHandler> = {
|
||||
}
|
||||
|
||||
const data = payload[id as keyof typeof payload];
|
||||
const patchEvent: Partial<OntimeEvent> & { id: string } = { id };
|
||||
const patchEvent: PatchWithId<OntimeEvent> = { id };
|
||||
|
||||
let shouldThrottle = false;
|
||||
|
||||
@@ -76,11 +77,13 @@ const actionHandlers: Record<string, ActionHandler> = {
|
||||
});
|
||||
|
||||
if (shouldThrottle) {
|
||||
if (throttledUpdateEvent(patchEvent)) {
|
||||
if (throttledEditEvent(patchEvent)) {
|
||||
return { payload: 'throttled' };
|
||||
}
|
||||
} else {
|
||||
updateEvent(patchEvent);
|
||||
editEntry(patchEvent).catch((_error) => {
|
||||
/** No error handling */
|
||||
});
|
||||
}
|
||||
return { payload: 'success' };
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user