improve sharedFeed performance

This commit is contained in:
pa
2025-12-20 03:13:50 +09:00
committed by Natsumi
parent ccfa378b24
commit 5db09e9e01
+46 -10
View File
@@ -262,12 +262,13 @@ export const useSharedFeedStore = defineStore('SharedFeed', () => {
} else { } else {
return; return;
} }
const bias = new Date(Date.now() - 86400000).toJSON(); // 24 hours const bias = new Date(Date.now() - 1000 * 60 * 60 * 12).toJSON(); // 12 hours
const wristArr = []; const wristArr = [];
let w = 0; let w = 0;
const wristFilter = notificationsSettingsStore.sharedFeedFilters.wrist; const wristFilter = notificationsSettingsStore.sharedFeedFilters.wrist;
let currentUserLeaveTime = 0; let currentUserLeaveTime = 0;
let locationJoinTime = 0; let locationJoinTime = 0;
let earliestKeptTime = 0;
for (i = sessionTable.length - 1; i > -1; i--) { for (i = sessionTable.length - 1; i > -1; i--) {
const ctx = sessionTable[i]; const ctx = sessionTable[i];
if (ctx.created_at < bias) { if (ctx.created_at < bias) {
@@ -276,21 +277,30 @@ export const useSharedFeedStore = defineStore('SharedFeed', () => {
if (ctx.type === 'Notification') { if (ctx.type === 'Notification') {
continue; continue;
} }
let ctxTime = 0;
if (w >= 50 && earliestKeptTime > 0) {
ctxTime = Date.parse(ctx.created_at);
if (ctxTime < earliestKeptTime - 20 * 1000) {
break;
}
}
// on Location change remove OnPlayerLeft // on Location change remove OnPlayerLeft
if (ctx.type === 'LocationDestination') { if (ctx.type === 'LocationDestination') {
currentUserLeaveTime = Date.parse(ctx.created_at); if (!ctxTime) {
ctxTime = Date.parse(ctx.created_at);
}
currentUserLeaveTime = ctxTime;
const currentUserLeaveTimeOffset = const currentUserLeaveTimeOffset =
currentUserLeaveTime + 5 * 1000; currentUserLeaveTime + 5 * 1000;
for (var k = w - 1; k > -1; k--) { for (var k = w - 1; k > -1; k--) {
var feedItem = wristArr[k]; var feedItem = wristArr[k];
const feedItemTime = Date.parse(feedItem.created_at);
if ( if (
(feedItem.type === 'OnPlayerLeft' || (feedItem.type === 'OnPlayerLeft' ||
feedItem.type === 'BlockedOnPlayerLeft' || feedItem.type === 'BlockedOnPlayerLeft' ||
feedItem.type === 'MutedOnPlayerLeft') && feedItem.type === 'MutedOnPlayerLeft') &&
Date.parse(feedItem.created_at) >= feedItemTime >= currentUserLeaveTime &&
currentUserLeaveTime && feedItemTime <= currentUserLeaveTimeOffset
Date.parse(feedItem.created_at) <=
currentUserLeaveTimeOffset
) { ) {
wristArr.splice(k, 1); wristArr.splice(k, 1);
w--; w--;
@@ -299,17 +309,20 @@ export const useSharedFeedStore = defineStore('SharedFeed', () => {
} }
// on Location change remove OnPlayerJoined // on Location change remove OnPlayerJoined
if (ctx.type === 'Location') { if (ctx.type === 'Location') {
locationJoinTime = Date.parse(ctx.created_at); if (!ctxTime) {
ctxTime = Date.parse(ctx.created_at);
}
locationJoinTime = ctxTime;
const locationJoinTimeOffset = locationJoinTime + 20 * 1000; const locationJoinTimeOffset = locationJoinTime + 20 * 1000;
for (let k = w - 1; k > -1; k--) { for (let k = w - 1; k > -1; k--) {
let feedItem = wristArr[k]; let feedItem = wristArr[k];
const feedItemTime = Date.parse(feedItem.created_at);
if ( if (
(feedItem.type === 'OnPlayerJoined' || (feedItem.type === 'OnPlayerJoined' ||
feedItem.type === 'BlockedOnPlayerJoined' || feedItem.type === 'BlockedOnPlayerJoined' ||
feedItem.type === 'MutedOnPlayerJoined') && feedItem.type === 'MutedOnPlayerJoined') &&
Date.parse(feedItem.created_at) >= locationJoinTime && feedItemTime >= locationJoinTime &&
Date.parse(feedItem.created_at) <= feedItemTime <= locationJoinTimeOffset
locationJoinTimeOffset
) { ) {
wristArr.splice(k, 1); wristArr.splice(k, 1);
w--; w--;
@@ -351,6 +364,14 @@ export const useSharedFeedStore = defineStore('SharedFeed', () => {
} }
// BlockedOnPlayerJoined, BlockedOnPlayerLeft, MutedOnPlayerJoined, MutedOnPlayerLeft // BlockedOnPlayerJoined, BlockedOnPlayerLeft, MutedOnPlayerJoined, MutedOnPlayerLeft
if (ctx.type === 'OnPlayerJoined' || ctx.type === 'OnPlayerLeft') { if (ctx.type === 'OnPlayerJoined' || ctx.type === 'OnPlayerLeft') {
if (
ctx.userId &&
!moderationStore.cachedPlayerModerationsUserIds.has(
ctx.userId
)
) {
// no moderation for this userId, skip
} else {
for (var ref of moderationStore.cachedPlayerModerations.values()) { for (var ref of moderationStore.cachedPlayerModerations.values()) {
if ( if (
ref.targetDisplayName !== ctx.displayName && ref.targetDisplayName !== ctx.displayName &&
@@ -383,10 +404,18 @@ export const useSharedFeedStore = defineStore('SharedFeed', () => {
(wristFilter[type] === 'VIP' && isFavorite)) (wristFilter[type] === 'VIP' && isFavorite))
) { ) {
wristArr.unshift(entry); wristArr.unshift(entry);
const entryTime = Date.parse(entry.created_at);
if (
!earliestKeptTime ||
entryTime < earliestKeptTime
) {
earliestKeptTime = entryTime;
}
} }
notificationStore.queueGameLogNoty(entry); notificationStore.queueGameLogNoty(entry);
} }
} }
}
// when too many user joins happen at once when switching instances // when too many user joins happen at once when switching instances
// the "w" counter maxes out and wont add any more entries // the "w" counter maxes out and wont add any more entries
// until the onJoins are cleared by "Location" // until the onJoins are cleared by "Location"
@@ -406,8 +435,15 @@ export const useSharedFeedStore = defineStore('SharedFeed', () => {
isFavorite isFavorite
}); });
++w; ++w;
if (!ctxTime) {
ctxTime = Date.parse(ctx.created_at);
}
if (!earliestKeptTime || ctxTime < earliestKeptTime) {
earliestKeptTime = ctxTime;
} }
} }
}
wristArr.splice(50);
sharedFeed.value.gameLog.wrist = wristArr; sharedFeed.value.gameLog.wrist = wristArr;
sharedFeed.value.pendingUpdate = true; sharedFeed.value.pendingUpdate = true;
} }