optimizing topic load

This commit is contained in:
balzack 2023-03-02 20:51:20 -08:00
parent e4f55861d0
commit f5e27c80e1

View File

@ -61,6 +61,7 @@ export function useConversationContext() {
const cardValue = cardId ? card.state.cards.get(cardId) : null;
const channelValue = cardId ? cardValue?.channels.get(channelId) : channel.state.channels.get(channelId);
const { topicRevision } = channelValue || {};
let setChannel = false;
if (channelValue) {
if (!loaded.current) {
@ -75,6 +76,9 @@ export function useConversationContext() {
curTopicMarker.current = topicMarker;
loaded.current = true;
}
else {
setChannel = true;
}
}
else {
console.log("failed to load conversation");
@ -89,20 +93,25 @@ export function useConversationContext() {
await setMarkerAndSync(cardId, channelId, delta.marker, topicRevision);
curTopicMarker.current = delta.marker;
curSyncRevision.current = topicRevision;
updateState({ offsync: false, topics: topics.current, card: cardValue, channel: channelValue });
}
if (loadMore && marker) {
else if (loadMore && marker) {
const delta = await getTopicDelta(cardId, channelId, null, COUNT, null, curTopicMarker.current);
await setTopicDelta(cardId, channelId, delta.topics);
await setTopicMarker(cardId, channelId, delta.marker);
curTopicMarker.current = delta.marker;
updateState({ offsync: false, topics: topics.current, card: cardValue, channel: channelValue });
}
if (ignoreRevision || topicRevision !== curSyncRevision.current) {
else if (ignoreRevision || topicRevision !== curSyncRevision.current) {
const delta = await getTopicDelta(cardId, channelId, curSyncRevision.current, null, curTopicMarker.current, null);
await setTopicDelta(cardId, channelId, delta.topics);
await setSyncRevision(cardId, channelId, topicRevision);
curSyncRevision.current = topicRevision;
updateState({ offsync: false, topics: topics.current, card: cardValue, channel: channelValue });
}
else if (setChannel) {
updateState({ offsync: false, topics: topics.current, card: cardValue, channel: channelValue });
}
updateState({ offsync: false, topics: topics.current, card: cardValue, channel: channelValue });
}
catch(err) {
console.log(err);