refs #985 Ignore error for unique constraints in account cache
This commit is contained in:
parent
56c2387b8e
commit
9b459549dc
|
@ -25,11 +25,12 @@ export default class AccountCache {
|
|||
return new Promise((resolve, reject) => {
|
||||
// At first confirm records for unique.
|
||||
this.db.findOne<CachedAccount>({ owner_id: ownerID, acct: acct }, (err, doc) => {
|
||||
if (err) return reject(err)
|
||||
if (!isEmpty(doc)) return reject(new Error('Record already exists'))
|
||||
this.db.insert<CachedAccount>({ owner_id: ownerID, acct: acct }, (err, doc) => {
|
||||
if (err) return err
|
||||
// Ignore error for unique constraints.
|
||||
if (!isEmpty(doc)) return err
|
||||
return this.db.insert<CachedAccount>({ owner_id: ownerID, acct: acct }, (err, doc) => {
|
||||
if (err) return reject(err)
|
||||
resolve(doc)
|
||||
return resolve(doc)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
@ -474,8 +474,7 @@ ipcMain.on('start-all-user-streamings', (event: Event, accounts: Array<LocalAcco
|
|||
await hashtagCache.insertHashtag(tag.name)
|
||||
})
|
||||
// Cache account
|
||||
// Ignore error for unique constratins.
|
||||
await accountCache.insertAccount(id, update.account.acct).catch(err => console.info(err))
|
||||
await accountCache.insertAccount(id, update.account.acct).catch(err => console.error(err))
|
||||
},
|
||||
(notification: RemoteNotification) => {
|
||||
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) => {
|
||||
const { ownerID, accts } = obj
|
||||
accts.map(async acct => {
|
||||
// Ignore error for unique constratins.
|
||||
await accountCache.insertAccount(ownerID, acct).catch(err => console.info(err))
|
||||
await accountCache.insertAccount(ownerID, acct).catch(err => console.error(err))
|
||||
})
|
||||
event.sender.send('response-insert-cache-accounts')
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue