Skip to content

Commit 7e28012

Browse files
authored
fix: do no register model once cached (#26)
Signed-off-by: kerthcet <kerthcet@gmail.com>
1 parent b771bf1 commit 7e28012

3 files changed

Lines changed: 22 additions & 14 deletions

File tree

src/cli/commands.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ pub async fn run(cli: Cli) {
8989

9090
let mut table = Table::new();
9191
table.set_format(*format::consts::FORMAT_CLEAN);
92-
table.add_row(row!["MODEL", "PROVIDER", "REVISION", "SIZE", "CREATED"]);
92+
table.add_row(row!["MODEL", "PROVIDER", "REVISION", "SIZE", "MODIFIED"]);
9393

9494
for model in models {
9595
let size_str = format_size_decimal(model.size);
@@ -100,7 +100,7 @@ pub async fn run(cli: Cli) {
100100
&model.revision
101101
};
102102

103-
let created_str = format_time_ago(&model.created_at);
103+
let created_str = format_time_ago(&model.modified_at);
104104

105105
table.add_row(row![
106106
model.name,

src/downloader/huggingface.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,12 @@ impl Downloader for HuggingFaceDownloader {
9999
let sha = model_info.sha.clone();
100100
let snapshot_path = model_cache_path.join("snapshots").join(&sha);
101101

102+
// Check if all files are already cached
103+
let model_totally_cached = model_info
104+
.siblings
105+
.iter()
106+
.all(|sibling| snapshot_path.join(&sibling.rfilename).exists());
107+
102108
// Process all files in manifest order (cached files show as instantly complete)
103109
let mut tasks = Vec::new();
104110

@@ -168,14 +174,16 @@ impl Downloader for HuggingFaceDownloader {
168174
provider: "huggingface".to_string(),
169175
revision: sha,
170176
size: downloaded_size,
171-
created_at: chrono::Local::now().to_rfc3339(),
177+
modified_at: chrono::Local::now().to_rfc3339(),
172178
cache_path: model_cache_path.to_string_lossy().to_string(),
173179
};
174180

175-
let registry = ModelRegistry::new(None);
176-
registry
177-
.register_model(model_info_record)
178-
.map_err(|e| DownloadError::ApiError(format!("Failed to register model: {}", e)))?;
181+
if !model_totally_cached {
182+
let registry = ModelRegistry::new(None);
183+
registry
184+
.register_model(model_info_record)
185+
.map_err(|e| DownloadError::ApiError(format!("Failed to register model: {}", e)))?;
186+
}
179187

180188
println!(
181189
"\n{} {} {} {} {:.2?}",

src/registry/model_registry.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ pub struct ModelInfo {
1111
pub provider: String,
1212
pub revision: String,
1313
pub size: u64,
14-
pub created_at: String,
14+
pub modified_at: String,
1515
pub cache_path: String,
1616
}
1717

@@ -122,7 +122,7 @@ mod tests {
122122
provider: "huggingface".to_string(),
123123
revision: "abc123".to_string(),
124124
size: 1000,
125-
created_at: "2025-01-01T00:00:00Z".to_string(),
125+
modified_at: "2025-01-01T00:00:00Z".to_string(),
126126
cache_path: "/tmp/test".to_string(),
127127
};
128128

@@ -143,7 +143,7 @@ mod tests {
143143
provider: "huggingface".to_string(),
144144
revision: "abc123".to_string(),
145145
size: 1000,
146-
created_at: "2025-01-01T00:00:00Z".to_string(),
146+
modified_at: "2025-01-01T00:00:00Z".to_string(),
147147
cache_path: "/tmp/test".to_string(),
148148
};
149149

@@ -164,7 +164,7 @@ mod tests {
164164
provider: "huggingface".to_string(),
165165
revision: "abc123".to_string(),
166166
size: 1000,
167-
created_at: "2025-01-01T00:00:00Z".to_string(),
167+
modified_at: "2025-01-01T00:00:00Z".to_string(),
168168
cache_path: "/tmp/test".to_string(),
169169
};
170170

@@ -198,7 +198,7 @@ mod tests {
198198
provider: "huggingface".to_string(),
199199
revision: "abc123".to_string(),
200200
size: 1000,
201-
created_at: "2025-01-01T00:00:00Z".to_string(),
201+
modified_at: "2025-01-01T00:00:00Z".to_string(),
202202
cache_path: "/tmp/test".to_string(),
203203
};
204204

@@ -209,7 +209,7 @@ mod tests {
209209
provider: "huggingface".to_string(),
210210
revision: "def456".to_string(),
211211
size: 2000,
212-
created_at: "2025-01-02T00:00:00Z".to_string(),
212+
modified_at: "2025-01-02T00:00:00Z".to_string(),
213213
cache_path: "/tmp/test2".to_string(),
214214
};
215215

@@ -236,7 +236,7 @@ mod tests {
236236
provider: "huggingface".to_string(),
237237
revision: "abc123".to_string(),
238238
size: 1000,
239-
created_at: "2025-01-01T00:00:00Z".to_string(),
239+
modified_at: "2025-01-01T00:00:00Z".to_string(),
240240
cache_path: cache_dir.to_string_lossy().to_string(),
241241
};
242242

0 commit comments

Comments
 (0)