refs #985 Save account cache when updated

This commit is contained in:
AkiraFukushima 2019-08-10 18:31:50 +09:00
parent e01156df08
commit 93a7ae5148
2 changed files with 11 additions and 4 deletions

View File

@ -465,7 +465,7 @@ ipcMain.on('start-all-user-streamings', (event: Event, accounts: Array<LocalAcco
const url = await StreamingURL(acct)
userStreamings[id] = new WebSocket(acct, url)
userStreamings[id]!.startUserStreaming(
(update: Status) => {
async (update: Status) => {
if (!event.sender.isDestroyed()) {
event.sender.send(`update-start-all-user-streamings-${id}`, update)
}
@ -473,6 +473,9 @@ ipcMain.on('start-all-user-streamings', (event: Event, accounts: Array<LocalAcco
update.tags.map(async tag => {
await hashtagCache.insertHashtag(tag.name)
})
// Cache account
// Ignore error for unique constratins.
await accountCache.insertAccount(id, update.account.acct).catch(err => console.info(err))
},
(notification: RemoteNotification) => {
const preferences = new Preferences(preferencesDBPath)
@ -1021,9 +1024,8 @@ ipcMain.on('get-cache-accounts', async (event: Event, ownerID: string) => {
ipcMain.on('insert-cache-accounts', (event: Event, obj: InsertAccountCache) => {
const { ownerID, accts } = obj
accts.map(async acct => {
await accountCache.insertAccount(ownerID, acct).catch(err => {
console.warn(err)
})
// Ignore error for unique constratins.
await accountCache.insertAccount(ownerID, acct).catch(err => console.info(err))
})
event.sender.send('response-insert-cache-accounts')
})

View File

@ -4,6 +4,7 @@ import Mastodon, { Account, Tag, Response, Results } from 'megalodon'
import { Module, MutationTree, ActionTree, GetterTree } from 'vuex'
import { RootState } from '@/store/index'
import { LocalTag } from '~/src/types/localTag'
import { InsertAccountCache } from '~/src/types/insertAccountCache'
type Suggest = {
name: string
@ -113,6 +114,10 @@ const actions: ActionTree<StatusState, RootState> = {
const res: Response<Results> = await client.get<Results>('/search', { q: word, resolve: false })
commit(MUTATION_TYPES.UPDATE_FILTERED_ACCOUNTS, res.data.accounts)
if (res.data.accounts.length === 0) throw new Error('Empty')
ipcRenderer.send('insert-cache-accounts', {
ownerID: rootState.TimelineSpace.account._id!,
accts: res.data.accounts.map(a => a.acct)
} as InsertAccountCache)
commit(MUTATION_TYPES.CHANGE_OPEN_SUGGEST, true)
commit(MUTATION_TYPES.CHANGE_START_INDEX, start)
commit(MUTATION_TYPES.CHANGE_MATCH_WORD, word)