fix the exception caused by race condition
Signed-off-by: James <james@jan.ai>
This commit is contained in:
parent
f7a7752d0d
commit
a289e6e276
@ -190,75 +190,83 @@ function getUnfinishedDownloadModels() {
|
|||||||
|
|
||||||
async function getFinishedDownloadModels() {
|
async function getFinishedDownloadModels() {
|
||||||
const db = new sqlite3.Database(getDbPath());
|
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 query = `SELECT * FROM model_versions WHERE finish_download_at != -1 ORDER BY finish_download_at DESC`;
|
||||||
const modelVersions: any = await new Promise((resolve, reject) => {
|
const modelVersions: any = await new Promise((resolve, reject) => {
|
||||||
db.all(query, (err: Error, rows: any[]) => {
|
db.all(query, (err: Error, rows: any[]) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
reject(err);
|
reject(err);
|
||||||
} else {
|
} else {
|
||||||
resolve(rows);
|
resolve(rows);
|
||||||
}
|
}
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
const models = await Promise.all(
|
|
||||||
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) => {
|
|
||||||
if (err) {
|
|
||||||
reject(err);
|
|
||||||
} else {
|
|
||||||
resolve(row);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
})
|
});
|
||||||
);
|
|
||||||
|
|
||||||
const downloadedModels = [];
|
const models = await Promise.all(
|
||||||
modelVersions.forEach((modelVersion: any) => {
|
modelVersions.map(async (modelVersion) => {
|
||||||
const model = models.find((m: any) => m.id === modelVersion.model_id);
|
const modelQuery = `SELECT * FROM models WHERE id = ?`;
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
db.get(
|
||||||
|
modelQuery,
|
||||||
|
[modelVersion.model_id],
|
||||||
|
(err: Error, row: any) => {
|
||||||
|
if (err) {
|
||||||
|
reject(err);
|
||||||
|
} else {
|
||||||
|
resolve(row);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
if (!model) {
|
const downloadedModels = [];
|
||||||
return;
|
modelVersions.forEach((modelVersion: any) => {
|
||||||
}
|
const model = models.find((m: any) => m.id === modelVersion.model_id);
|
||||||
|
|
||||||
const assistantModel = {
|
if (!model) {
|
||||||
id: modelVersion.id,
|
return;
|
||||||
name: modelVersion.name,
|
}
|
||||||
quantMethod: modelVersion.quant_method,
|
|
||||||
bits: modelVersion.bits,
|
|
||||||
size: modelVersion.size,
|
|
||||||
maxRamRequired: modelVersion.max_ram_required,
|
|
||||||
usecase: modelVersion.usecase,
|
|
||||||
downloadLink: modelVersion.download_link,
|
|
||||||
startDownloadAt: modelVersion.start_download_at,
|
|
||||||
finishDownloadAt: modelVersion.finish_download_at,
|
|
||||||
productId: model.id,
|
|
||||||
productName: model.name,
|
|
||||||
shortDescription: model.short_description,
|
|
||||||
longDescription: model.long_description,
|
|
||||||
avatarUrl: model.avatar_url,
|
|
||||||
author: model.author,
|
|
||||||
version: model.version,
|
|
||||||
modelUrl: model.model_url,
|
|
||||||
nsfw: model.nsfw === 0 ? false : true,
|
|
||||||
greeting: model.default_greeting,
|
|
||||||
type: model.type,
|
|
||||||
createdAt: new Date(model.created_at).getTime(),
|
|
||||||
updatedAt: new Date(model.updated_at ?? "").getTime(),
|
|
||||||
status: "",
|
|
||||||
releaseDate: -1,
|
|
||||||
tags: model.tags.split(","),
|
|
||||||
};
|
|
||||||
downloadedModels.push(assistantModel);
|
|
||||||
});
|
|
||||||
|
|
||||||
db.close();
|
const assistantModel = {
|
||||||
|
id: modelVersion.id,
|
||||||
|
name: modelVersion.name,
|
||||||
|
quantMethod: modelVersion.quant_method,
|
||||||
|
bits: modelVersion.bits,
|
||||||
|
size: modelVersion.size,
|
||||||
|
maxRamRequired: modelVersion.max_ram_required,
|
||||||
|
usecase: modelVersion.usecase,
|
||||||
|
downloadLink: modelVersion.download_link,
|
||||||
|
startDownloadAt: modelVersion.start_download_at,
|
||||||
|
finishDownloadAt: modelVersion.finish_download_at,
|
||||||
|
productId: model.id,
|
||||||
|
productName: model.name,
|
||||||
|
shortDescription: model.short_description,
|
||||||
|
longDescription: model.long_description,
|
||||||
|
avatarUrl: model.avatar_url,
|
||||||
|
author: model.author,
|
||||||
|
version: model.version,
|
||||||
|
modelUrl: model.model_url,
|
||||||
|
nsfw: model.nsfw === 0 ? false : true,
|
||||||
|
greeting: model.default_greeting,
|
||||||
|
type: model.type,
|
||||||
|
createdAt: new Date(model.created_at).getTime(),
|
||||||
|
updatedAt: new Date(model.updated_at ?? "").getTime(),
|
||||||
|
status: "",
|
||||||
|
releaseDate: -1,
|
||||||
|
tags: model.tags.split(","),
|
||||||
|
};
|
||||||
|
downloadedModels.push(assistantModel);
|
||||||
|
});
|
||||||
|
|
||||||
return downloadedModels;
|
db.close();
|
||||||
|
|
||||||
|
return downloadedModels;
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err);
|
||||||
|
return [];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function deleteDownloadModel(modelId: string) {
|
function deleteDownloadModel(modelId: string) {
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "data-plugin",
|
"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",
|
"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",
|
"icon": "https://raw.githubusercontent.com/tailwindlabs/heroicons/88e98b0c2b458553fbadccddc2d2f878edc0387b/src/20/solid/circle-stack.svg",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user