feat: add hourly portfolio sync history
This commit is contained in:
@@ -135,50 +135,14 @@ export class BrokerageOperationsService {
|
||||
? [{ accountId: source.accountId, from: source.from, to: source.to }]
|
||||
: [],
|
||||
);
|
||||
if (query.sync !== 'observe') {
|
||||
const discovery = await this.membership.request(
|
||||
userId,
|
||||
connection.revision,
|
||||
);
|
||||
if (discovery) {
|
||||
void discovery.done
|
||||
.then(async () => {
|
||||
const current = await this.access.local(userId, accountId);
|
||||
if (current.revision !== connection.revision) return;
|
||||
const currentRange = ledgerRange(
|
||||
query.from,
|
||||
query.to,
|
||||
query.instrumentUid,
|
||||
current.accounts.filter(
|
||||
(account) =>
|
||||
accountId === 'all' || account.accountId === accountId,
|
||||
),
|
||||
now,
|
||||
);
|
||||
const targets = current.accounts
|
||||
.filter(
|
||||
(account) =>
|
||||
accountId === 'all' || account.accountId === accountId,
|
||||
)
|
||||
.flatMap((account) =>
|
||||
currentRange.from < currentRange.to
|
||||
? [{ accountId: account.accountId, ...currentRange }]
|
||||
: [],
|
||||
);
|
||||
await this.sync.readPlan(userId, targets, {
|
||||
movingEnd,
|
||||
history: true,
|
||||
revision: connection.revision,
|
||||
});
|
||||
})
|
||||
.catch(() => undefined);
|
||||
} else if (intervals.length) {
|
||||
await this.sync.readPlan(userId, intervals, {
|
||||
movingEnd,
|
||||
history: true,
|
||||
revision: connection.revision,
|
||||
});
|
||||
}
|
||||
// The ledger only starts the first-time load of missing intervals; the
|
||||
// mutable tail belongs to the hourly walk and membership is not rechecked.
|
||||
if (intervals.length) {
|
||||
await this.sync.readPlan(userId, intervals, {
|
||||
movingEnd,
|
||||
history: true,
|
||||
revision: connection.revision,
|
||||
});
|
||||
}
|
||||
const saved = await this.repository.readPage(readInput);
|
||||
const accounts = saved?.connection.accounts ?? [];
|
||||
@@ -252,26 +216,10 @@ export class BrokerageOperationsService {
|
||||
dataRevision: value.dataRevision,
|
||||
availability: 'complete',
|
||||
fetchedAt: value.fetchedAt,
|
||||
freshForMs: tbankSourceTtlMs.metadata,
|
||||
freshForMs: tbankSourceTtlMs.portfolio,
|
||||
work: null,
|
||||
}),
|
||||
);
|
||||
if (query.sync !== 'observe') {
|
||||
const identities = new Map(
|
||||
rows.map((row) => {
|
||||
const identity = row.payload as TbankOperationItem;
|
||||
return [
|
||||
metadataKey(identity),
|
||||
{ instrumentUid: identity.instrumentUid, figi: identity.figi },
|
||||
] as const;
|
||||
}),
|
||||
);
|
||||
for (const identity of identities.values()) {
|
||||
if (!instruments.get(metadataKey(identity))?.fresh) {
|
||||
await this.metadata.request(userId, connection.revision, identity);
|
||||
}
|
||||
}
|
||||
}
|
||||
const membershipMeta = investmentResourceMeta({
|
||||
resourceKey: 'accounts/membership',
|
||||
dataRevision: String(saved?.connection.membershipRevision ?? MISSING_MEMBERSHIP_REVISION),
|
||||
|
||||
Reference in New Issue
Block a user