Skip to content
This repository was archived by the owner on Jul 4, 2025. It is now read-only.

Commit 601437d

Browse files
fix: cache by download item id (#1599)
Co-authored-by: vansangpfiev <sang@jan.ai>
1 parent 0ebada2 commit 601437d

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

engine/cli/commands/model_pull_cmd.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ std::optional<std::string> ModelPullCmd::Exec(const std::string& host, int port,
103103
CTL_INF("model: " << model << ", model_id: " << model_id);
104104

105105
// Send request download model to server
106+
CLI_LOG("Validating download items, please wait..")
106107
Json::Value json_data;
107108
json_data["model"] = model;
108109
auto data_str = json_data.toStyledString();

engine/cli/utils/download_progress.cc

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ bool DownloadProgress::Connect(const std::string& host, int port) {
2323

2424
bool DownloadProgress::Handle(const std::string& id) {
2525
assert(!!ws_);
26-
uint64_t total = std::numeric_limits<uint64_t>::max();
26+
std::unordered_map<std::string, uint64_t> totals;
2727
status_ = DownloadStatus::DownloadStarted;
2828
std::unique_ptr<indicators::DynamicProgress<indicators::ProgressBar>> bars;
2929

3030
std::vector<std::unique_ptr<indicators::ProgressBar>> items;
3131
indicators::show_console_cursor(false);
32-
auto handle_message = [this, &bars, &items, &total,
32+
auto handle_message = [this, &bars, &items, &totals,
3333
id](const std::string& message) {
3434
CTL_INF(message);
3535

@@ -72,23 +72,26 @@ bool DownloadProgress::Handle(const std::string& id) {
7272
for (int i = 0; i < ev.download_task_.items.size(); i++) {
7373
auto& it = ev.download_task_.items[i];
7474
uint64_t downloaded = it.downloadedBytes.value_or(0);
75-
if (total == 0 || total == std::numeric_limits<uint64_t>::max()) {
76-
total = it.bytes.value_or(std::numeric_limits<uint64_t>::max());
77-
CTL_INF("Updated - total: " << total);
75+
if (totals.find(it.id) == totals.end()) {
76+
totals[it.id] = it.bytes.value_or(std::numeric_limits<uint64_t>::max());
77+
CTL_INF("Updated " << it.id << " - total: " << totals[it.id]);
7878
}
79-
if (ev.type_ == DownloadStatus::DownloadUpdated) {
79+
80+
if (ev.type_ == DownloadStatus::DownloadStarted ||
81+
ev.type_ == DownloadStatus::DownloadUpdated) {
8082
(*bars)[i].set_option(indicators::option::PrefixText{
8183
pad_string(it.id) +
82-
std::to_string(int(static_cast<double>(downloaded) / total * 100)) +
84+
std::to_string(
85+
int(static_cast<double>(downloaded) / totals[it.id] * 100)) +
8386
'%'});
8487
(*bars)[i].set_progress(
85-
int(static_cast<double>(downloaded) / total * 100));
88+
int(static_cast<double>(downloaded) / totals[it.id] * 100));
8689
(*bars)[i].set_option(indicators::option::PostfixText{
8790
format_utils::BytesToHumanReadable(downloaded) + "/" +
88-
format_utils::BytesToHumanReadable(total)});
91+
format_utils::BytesToHumanReadable(totals[it.id])});
8992
} else if (ev.type_ == DownloadStatus::DownloadSuccess) {
9093
(*bars)[i].set_progress(100);
91-
auto total_str = format_utils::BytesToHumanReadable(total);
94+
auto total_str = format_utils::BytesToHumanReadable(totals[it.id]);
9295
(*bars)[i].set_option(
9396
indicators::option::PostfixText{total_str + "/" + total_str});
9497
(*bars)[i].set_option(

0 commit comments

Comments
 (0)