Skip to content

Commit

Permalink
fix: failed to query data when only drop msglog table
Browse files Browse the repository at this point in the history
 - rename clearAllFts to dropAllFts
 - added clearAllFts func using `DELETE FROM nim_msglog`
 - added clearAllFts test button to example

Signed-off-by: 邓佳佳 <[email protected]>
  • Loading branch information
邓佳佳 committed Jul 22, 2021
1 parent e023923 commit c2e807a
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 20 deletions.
17 changes: 9 additions & 8 deletions example/domAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,14 @@ window.onload = (function () {
.catch(() => {
alert('清空失败!')
})
} else if (hasClass(target, 'j-drop')) {
window.nim && window.nim.dropAllFts()
.then(() => {
alert('删除所有表并重建成功')
})
.catch(() => {
alert('操作失败!')
})
}
// 同步消息
else if (hasClass(target, 'j-sync')) {
Expand Down Expand Up @@ -170,16 +178,9 @@ function doSyncByLimit(start = 0) {
types: ['text', 'custom'], // 只针对文本消息和自定义消息
limit: 3000,
done(error, obj) {
// console.log(
// '获取并同步本地消息' + (!error ? '成功' : '失败'),
// error,
// '结束时间 ' + new Date(end),
// // '共 ' + obj.msgs && obj.msgs.length + ' 条'
// )

if (obj.msgs && obj.msgs.length > 0) {
window.total += obj.msgs.length;
// console.timeEnd('doSyncByLimit')
const time = obj.msgs[obj.msgs.length - 1].time
doSyncByLimit(time)
}
},
Expand Down
3 changes: 2 additions & 1 deletion example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,9 @@ <h3>批量单向删除消息 deleteMsgSelfBatch</h3>
<button class="j-send-diy">删除</button>
</div> -->
<div>
<h3>清空searchDB clearAllFts</h3>
<h3>清空 FTS 表及重建 FTS 表</h3>
<button class="j-clear">清空</button>
<button class="j-drop">重建</button>
</div>

<!-- You can also require other files to run in this process -->
Expand Down
2 changes: 1 addition & 1 deletion example/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function doLog(err, obj) {
}

NIM.getInstance({
debug: true,
debug: false,
appKey: 'fe416640c8e8a72734219e1847ad2547',
account: 'cs6',
token: 'e10adc3949ba59abbe56e057f20f883e',
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "kit-fullsearch-electron",
"version": "2.1.0-alpha.4",
"version": "2.1.0-alpha.2",
"description": "全文搜索组件,基于网易云信web端im sdk,用于Electron",
"main": "lib/index.js",
"module": "lib/index.js",
Expand Down
26 changes: 17 additions & 9 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ const fullText = (NimSdk: any) => {
nim_msglog_fts,rowid,idClient,text,sessionId,[from],
time,target,[to],type,scene,idServer,fromNick,content
) VALUES (
'delete',old.idClient,old.text,old.sessionId,old.[from],old.time,old.target,
'delete',old.id,old.idClient,old.text,old.sessionId,old.[from],old.time,old.target,
old.[to],old.type,old.scene,old.idServer,old.fromNick,old.content
);
END;`
Expand Down Expand Up @@ -583,20 +583,28 @@ const fullText = (NimSdk: any) => {

public async clearAllFts(): Promise<void> {
try {
await this.searchDB.run('drop table if exists nim_msglog')
await this.searchDB.run('drop table if exists nim_msglog_fts')
await this.searchDB.run('drop table if exists nim_msglog_au')
await this.searchDB.run('drop table if exists nim_msglog_ai')
await this.searchDB.run('drop table if exists nim_msglog_ad')
await this.createTable()

this.ftLogFunc('clearAllFts success')
await this.searchDB.run('DELETE FROM `nim_msglog`;')
} catch (error) {
this.ftLogFunc('clearAllFts fail: ', error)
throw error
}
}

public async dropAllFts(): Promise<void> {
try {
await this.searchDB.run('drop table if exists nim_msglog;')
await this.searchDB.run('drop table if exists nim_msglog_fts;')
await this.searchDB.run('drop trigger if exists nim_msglog_au;')
await this.searchDB.run('drop trigger if exists nim_msglog_ai;')
await this.searchDB.run('drop trigger if exists nim_msglog_ad;')
await this.createTable()
this.ftLogFunc('dropAllFts success')
} catch (error) {
this.ftLogFunc('dropAllFts fail: ', error)
throw error
}
}

public destroy(...args: any): void {
new Promise((resolve, reject) => {
this.searchDB.close(function (err) {
Expand Down

0 comments on commit c2e807a

Please sign in to comment.