mirror of
https://github.com/SableClient/Sable.git
synced 2026-11-21 09:31:17 -08:00
fix: populate versions cache and refresh thread support
This commit is contained in:
1 parent
ef10ad4243
commit
a76acdf819
2 files changed
+24
-2
No files matched your search
@@ -33,6 +33,7 @@ import {
|
||||
primeVersionsFromCache,
|
||||
revalidateVersionsCache,
|
||||
clearCachedVersions,
|
||||
cacheVersionsFromClient,
|
||||
} from './versionsCache';
|
||||
|
||||
const log = createLogger('initMatrix');
|
||||
@@ -281,7 +282,7 @@ const initializeClient = async (
|
||||
|
||||
void primeVersionsFromCache(mx, session.baseUrl, session.userId).then((primed) => {
|
||||
if (primed) void revalidateVersionsCache(mx, session.baseUrl, session.userId);
|
||||
else void mx.getVersions().catch(() => undefined);
|
||||
else void cacheVersionsFromClient(mx, session.baseUrl, session.userId);
|
||||
});
|
||||
|
||||
const syncStorePromise = measureStartupPhase('sync_store', () => indexedDBStore.startup());
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { MatrixClient } from '$types/matrix-sdk';
|
||||
import { buildFeatureSupportMap, Method } from '$types/matrix-sdk';
|
||||
import { buildFeatureSupportMap, Method, Thread } from '$types/matrix-sdk';
|
||||
|
||||
const TTL_MS = 24 * 60 * 60 * 1000; // 24 hours
|
||||
const keyFor = (baseUrl: string, userId: string): string =>
|
||||
@@ -37,6 +37,23 @@ const writeCache = (
|
||||
}
|
||||
};
|
||||
|
||||
/** Fetch /versions through the SDK and persist the response for the next startup. */
|
||||
export const cacheVersionsFromClient = async (
|
||||
mx: MatrixClient,
|
||||
baseUrl: string,
|
||||
userId: string
|
||||
): Promise<void> => {
|
||||
try {
|
||||
const data = await mx.getVersions();
|
||||
writeCache(baseUrl, userId, {
|
||||
versions: data.versions,
|
||||
unstable_features: data.unstable_features,
|
||||
});
|
||||
} catch {
|
||||
// startup can continue without a cache entry.
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Seed mx.serverVersionsPromise AND mx.canSupport from a cached /versions payload.
|
||||
* Seeding the promise alone leaves canSupport empty → semantic drift in
|
||||
@@ -87,6 +104,10 @@ export const revalidateVersionsCache = async (
|
||||
).serverVersionsPromise = Promise.resolve(data);
|
||||
(mx as unknown as { canSupport: Map<unknown, unknown> }).canSupport =
|
||||
await buildFeatureSupportMap(data as Parameters<typeof buildFeatureSupportMap>[0]);
|
||||
const { threads, list, fwdPagination } = await mx.doesServerSupportThread();
|
||||
Thread.setServerSideSupport(threads);
|
||||
Thread.setServerSideListSupport(list);
|
||||
Thread.setServerSideFwdPaginationSupport(fwdPagination);
|
||||
} catch {
|
||||
// Revalidation failed — cached values remain in effect. Non-fatal.
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user