fix status thread update logic (#524)
This commit is contained in:
parent
96c2858d7a
commit
2f1e4077ea
|
@ -6,6 +6,7 @@ import uniq from 'lodash-es/uniq'
|
||||||
import isEqual from 'lodash-es/isEqual'
|
import isEqual from 'lodash-es/isEqual'
|
||||||
import { database } from '../_database/database'
|
import { database } from '../_database/database'
|
||||||
import { runMediumPriorityTask } from '../_utils/runMediumPriorityTask'
|
import { runMediumPriorityTask } from '../_utils/runMediumPriorityTask'
|
||||||
|
import { concat } from '../_utils/arrays'
|
||||||
|
|
||||||
const STREAMING_THROTTLE_DELAY = 3000
|
const STREAMING_THROTTLE_DELAY = 3000
|
||||||
|
|
||||||
|
@ -30,7 +31,7 @@ async function insertUpdatesIntoTimeline (instanceName, timelineName, updates) {
|
||||||
await database.insertTimelineItems(instanceName, timelineName, updates)
|
await database.insertTimelineItems(instanceName, timelineName, updates)
|
||||||
|
|
||||||
let itemIdsToAdd = store.getForTimeline(instanceName, timelineName, 'itemIdsToAdd') || []
|
let itemIdsToAdd = store.getForTimeline(instanceName, timelineName, 'itemIdsToAdd') || []
|
||||||
let newItemIdsToAdd = uniq([].concat(itemIdsToAdd).concat(updates.map(_ => _.id)))
|
let newItemIdsToAdd = uniq(concat(itemIdsToAdd, updates.map(_ => _.id)))
|
||||||
if (!isEqual(itemIdsToAdd, newItemIdsToAdd)) {
|
if (!isEqual(itemIdsToAdd, newItemIdsToAdd)) {
|
||||||
console.log('adding ', (newItemIdsToAdd.length - itemIdsToAdd.length),
|
console.log('adding ', (newItemIdsToAdd.length - itemIdsToAdd.length),
|
||||||
'items to itemIdsToAdd for timeline', timelineName)
|
'items to itemIdsToAdd for timeline', timelineName)
|
||||||
|
@ -47,14 +48,16 @@ async function insertUpdatesIntoThreads (instanceName, updates) {
|
||||||
|
|
||||||
for (let timelineName of Object.keys(threads)) {
|
for (let timelineName of Object.keys(threads)) {
|
||||||
let thread = threads[timelineName]
|
let thread = threads[timelineName]
|
||||||
let updatesForThisThread = updates.filter(
|
let itemIdsToAdd = store.getForTimeline(instanceName, timelineName, 'itemIdsToAdd') || []
|
||||||
status => thread.includes(status.in_reply_to_id) && !thread.includes(status.id)
|
let updatesForThisThread = updates.filter(status => (
|
||||||
)
|
thread.includes(status.in_reply_to_id) &&
|
||||||
|
!thread.includes(status.id) &&
|
||||||
|
!itemIdsToAdd.includes(status.id)
|
||||||
|
))
|
||||||
if (!updatesForThisThread.length) {
|
if (!updatesForThisThread.length) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
let itemIdsToAdd = store.getForTimeline(instanceName, timelineName, 'itemIdsToAdd') || []
|
let newItemIdsToAdd = uniq(concat(itemIdsToAdd, updatesForThisThread.map(_ => _.id)))
|
||||||
let newItemIdsToAdd = uniq([].concat(itemIdsToAdd).concat(updatesForThisThread.map(_ => _.id)))
|
|
||||||
if (!isEqual(itemIdsToAdd, newItemIdsToAdd)) {
|
if (!isEqual(itemIdsToAdd, newItemIdsToAdd)) {
|
||||||
console.log('adding ', (newItemIdsToAdd.length - itemIdsToAdd.length),
|
console.log('adding ', (newItemIdsToAdd.length - itemIdsToAdd.length),
|
||||||
'items to itemIdsToAdd for thread', timelineName)
|
'items to itemIdsToAdd for thread', timelineName)
|
||||||
|
@ -91,7 +94,7 @@ export function addStatusOrNotification (instanceName, timelineName, newStatusOr
|
||||||
export function addStatusesOrNotifications (instanceName, timelineName, newStatusesOrNotifications) {
|
export function addStatusesOrNotifications (instanceName, timelineName, newStatusesOrNotifications) {
|
||||||
console.log('addStatusesOrNotifications', Date.now())
|
console.log('addStatusesOrNotifications', Date.now())
|
||||||
let freshUpdates = store.getForTimeline(instanceName, timelineName, 'freshUpdates') || []
|
let freshUpdates = store.getForTimeline(instanceName, timelineName, 'freshUpdates') || []
|
||||||
freshUpdates = [].concat(freshUpdates).concat(newStatusesOrNotifications)
|
freshUpdates = concat(freshUpdates, newStatusesOrNotifications)
|
||||||
freshUpdates = uniqBy(freshUpdates, _ => _.id)
|
freshUpdates = uniqBy(freshUpdates, _ => _.id)
|
||||||
store.setForTimeline(instanceName, timelineName, { freshUpdates: freshUpdates })
|
store.setForTimeline(instanceName, timelineName, { freshUpdates: freshUpdates })
|
||||||
lazilyProcessFreshUpdates(instanceName, timelineName)
|
lazilyProcessFreshUpdates(instanceName, timelineName)
|
||||||
|
|
Loading…
Reference in a new issue