refs #985 Add cache db for hashtags
This commit is contained in:
parent
e3b5ef364d
commit
7301970495
|
@ -0,0 +1,29 @@
|
||||||
|
import Datastore from 'nedb'
|
||||||
|
import { LocalTag } from '~/src/types/localTag'
|
||||||
|
|
||||||
|
export default class HashtagCache {
|
||||||
|
private db: Datastore
|
||||||
|
|
||||||
|
constructor(db: Datastore) {
|
||||||
|
this.db = db
|
||||||
|
this.db.ensureIndex({ fieldName: 'tagName', unique: true }, _ => {})
|
||||||
|
}
|
||||||
|
|
||||||
|
listTags(): Promise<Array<LocalTag>> {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
this.db.find<LocalTag>({}, (err, docs) => {
|
||||||
|
if (err) return reject(err)
|
||||||
|
resolve(docs)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
insertHashtag(tag: string): Promise<LocalTag> {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
this.db.insert({ tagName: tag }, (err, doc) => {
|
||||||
|
if (err) return reject(err)
|
||||||
|
resolve(doc)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
|
@ -40,6 +40,7 @@ import { LocalTag } from '~/src/types/localTag'
|
||||||
import { UnreadNotification as UnreadNotificationConfig } from '~/src/types/unreadNotification'
|
import { UnreadNotification as UnreadNotificationConfig } from '~/src/types/unreadNotification'
|
||||||
import { Notify } from '~/src/types/notify'
|
import { Notify } from '~/src/types/notify'
|
||||||
import { StreamingError } from '~/src/errors/streamingError'
|
import { StreamingError } from '~/src/errors/streamingError'
|
||||||
|
import HashtagCache from './cache/hashtag'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Context menu
|
* Context menu
|
||||||
|
@ -100,6 +101,15 @@ unreadNotification.initialize().catch((err: Error) => log.error(err))
|
||||||
|
|
||||||
const preferencesDBPath = process.env.NODE_ENV === 'production' ? userData + './db/preferences.json' : 'preferences.json'
|
const preferencesDBPath = process.env.NODE_ENV === 'production' ? userData + './db/preferences.json' : 'preferences.json'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cache path
|
||||||
|
*/
|
||||||
|
const hashtagCachePath = process.env.NODE_ENV === 'production' ? userData + '/cache/hashtag.db' : 'cache/hashtag.db'
|
||||||
|
const hashtagCacheDB = new Datastore({
|
||||||
|
filename: hashtagCachePath,
|
||||||
|
autoload: true
|
||||||
|
})
|
||||||
|
|
||||||
const soundBasePath =
|
const soundBasePath =
|
||||||
process.env.NODE_ENV === 'development' ? path.join(__dirname, '../../build/sounds/') : path.join(process.resourcesPath!, 'build/sounds/')
|
process.env.NODE_ENV === 'development' ? path.join(__dirname, '../../build/sounds/') : path.join(process.resourcesPath!, 'build/sounds/')
|
||||||
|
|
||||||
|
@ -984,6 +994,19 @@ ipcMain.on('update-unread-notification', (event: Event, config: UnreadNotificati
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// Cache
|
||||||
|
ipcMain.on('get-cache-hashtag', async (event: Event) => {
|
||||||
|
const db = new HashtagCache(hashtagCacheDB)
|
||||||
|
const tags = await db.listTags()
|
||||||
|
event.sender.send('response-get-cache-hashtag', tags)
|
||||||
|
})
|
||||||
|
|
||||||
|
ipcMain.on('insert-cache-hashtag', async (event: Event, name: string) => {
|
||||||
|
const db = new HashtagCache(hashtagCacheDB)
|
||||||
|
const tag = await db.insertHashtag(name)
|
||||||
|
event.sender.send('response-insert-cache-hashtag', tag)
|
||||||
|
})
|
||||||
|
|
||||||
// Application control
|
// Application control
|
||||||
ipcMain.on('relaunch', () => {
|
ipcMain.on('relaunch', () => {
|
||||||
app.relaunch()
|
app.relaunch()
|
||||||
|
|
Loading…
Reference in New Issue