refs #985 Ignore error for unique constraints in account cache

This commit is contained in:
AkiraFukushima 2019-08-10 22:30:30 +09:00
parent 56c2387b8e
commit 9b459549dc
2 changed files with 7 additions and 8 deletions

View File

@ -25,11 +25,12 @@ export default class AccountCache {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
// At first confirm records for unique. // At first confirm records for unique.
this.db.findOne<CachedAccount>({ owner_id: ownerID, acct: acct }, (err, doc) => { this.db.findOne<CachedAccount>({ owner_id: ownerID, acct: acct }, (err, doc) => {
if (err) return reject(err) if (err) return err
if (!isEmpty(doc)) return reject(new Error('Record already exists')) // Ignore error for unique constraints.
this.db.insert<CachedAccount>({ owner_id: ownerID, acct: acct }, (err, doc) => { if (!isEmpty(doc)) return err
return this.db.insert<CachedAccount>({ owner_id: ownerID, acct: acct }, (err, doc) => {
if (err) return reject(err) if (err) return reject(err)
resolve(doc) return resolve(doc)
}) })
}) })
}) })

View File

@ -474,8 +474,7 @@ ipcMain.on('start-all-user-streamings', (event: Event, accounts: Array<LocalAcco
await hashtagCache.insertHashtag(tag.name) await hashtagCache.insertHashtag(tag.name)
}) })
// Cache account // Cache account
// Ignore error for unique constratins. await accountCache.insertAccount(id, update.account.acct).catch(err => console.error(err))
await accountCache.insertAccount(id, update.account.acct).catch(err => console.info(err))
}, },
(notification: RemoteNotification) => { (notification: RemoteNotification) => {
const preferences = new Preferences(preferencesDBPath) const preferences = new Preferences(preferencesDBPath)
@ -1024,8 +1023,7 @@ ipcMain.on('get-cache-accounts', async (event: Event, ownerID: string) => {
ipcMain.on('insert-cache-accounts', (event: Event, obj: InsertAccountCache) => { ipcMain.on('insert-cache-accounts', (event: Event, obj: InsertAccountCache) => {
const { ownerID, accts } = obj const { ownerID, accts } = obj
accts.map(async acct => { accts.map(async acct => {
// Ignore error for unique constratins. await accountCache.insertAccount(ownerID, acct).catch(err => console.error(err))
await accountCache.insertAccount(ownerID, acct).catch(err => console.info(err))
}) })
event.sender.send('response-insert-cache-accounts') event.sender.send('response-insert-cache-accounts')
}) })