fix the exception caused by race condition
Signed-off-by: James <james@jan.ai>
This commit is contained in:
parent
f7a7752d0d
commit
a289e6e276
@ -190,7 +190,7 @@ function getUnfinishedDownloadModels() {
|
||||
|
||||
async function getFinishedDownloadModels() {
|
||||
const db = new sqlite3.Database(getDbPath());
|
||||
|
||||
try {
|
||||
const query = `SELECT * FROM model_versions WHERE finish_download_at != -1 ORDER BY finish_download_at DESC`;
|
||||
const modelVersions: any = await new Promise((resolve, reject) => {
|
||||
db.all(query, (err: Error, rows: any[]) => {
|
||||
@ -206,13 +206,17 @@ async function getFinishedDownloadModels() {
|
||||
modelVersions.map(async (modelVersion) => {
|
||||
const modelQuery = `SELECT * FROM models WHERE id = ?`;
|
||||
return new Promise((resolve, reject) => {
|
||||
db.get(modelQuery, [modelVersion.model_id], (err: Error, row: any) => {
|
||||
db.get(
|
||||
modelQuery,
|
||||
[modelVersion.model_id],
|
||||
(err: Error, row: any) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
} else {
|
||||
resolve(row);
|
||||
}
|
||||
});
|
||||
}
|
||||
);
|
||||
});
|
||||
})
|
||||
);
|
||||
@ -259,6 +263,10 @@ async function getFinishedDownloadModels() {
|
||||
db.close();
|
||||
|
||||
return downloadedModels;
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
function deleteDownloadModel(modelId: string) {
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "data-plugin",
|
||||
"version": "1.0.1",
|
||||
"version": "1.0.2",
|
||||
"description": "Jan Database Plugin efficiently stores conversation and model data using SQLite, providing accessible data management",
|
||||
"icon": "https://raw.githubusercontent.com/tailwindlabs/heroicons/88e98b0c2b458553fbadccddc2d2f878edc0387b/src/20/solid/circle-stack.svg",
|
||||
"main": "dist/index.js",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user