~quadrispro/cmus/trunk

« back to all changes in this revision

Viewing changes to job.c

  • Committer: Gregory Petrosyan
  • Author(s): Siim Salonen
  • Date: 2012-09-29 08:01:59 UTC
  • Revision ID: git-v1:151c330a881d666e4256d4c953e3f5f1fc6e89fa
Add option to skip initial metadata loading

When I use network filesystems and trying to add many tracks then it
takes hours to complete.
In my case ~45GB mp3 collection mounted with sshfs over 3G network.
skip_track_info false: worker job: 9586.65 (2.6h), 8531 tracks
skip_track_info true : worker job: 266.30, 9448 tracks (includes .jpg etc.)

When I have time and bandwith, I can reload track(s) metadata using
'update-cache' or 'win-update-cache' commands.

TODO: fetch tags when file starts playing

[gp: formatting + extra is_http_url() check]
Signed-off-by: Gregory Petrosyan <gregory.petrosyan@gmail.com>

Show diffs side-by-side

added added

removed removed

Lines of Context:
73
73
static int add_file_cue(const char *filename);
74
74
#endif
75
75
 
76
 
static void add_file(const char *filename)
 
76
static void add_file(const char *filename, int force)
77
77
{
78
78
        struct track_info *ti;
79
79
 
80
80
#ifdef CONFIG_CUE
81
 
        if (!is_cue_url(filename) && add_file_cue(filename))
82
 
                return;
 
81
        if (!is_cue_url(filename)) {
 
82
                if (force || lookup_cache_entry(filename, hash_str(filename)) == NULL) {
 
83
                        int done = add_file_cue(filename);
 
84
                        if (done)
 
85
                                return;
 
86
                }
 
87
        }
83
88
#endif
84
89
 
85
90
        cache_lock();
86
 
        ti = cache_get_ti(filename);
 
91
        ti = cache_get_ti(filename, force);
87
92
        cache_unlock();
88
93
 
89
94
        if (ti)
109
114
 
110
115
        for (int i = 1; i <= n_tracks; ++i) {
111
116
                url = construct_cue_url(cue_filename, i);
112
 
                add_file(url);
 
117
                add_file(url, 0);
113
118
                free(url);
114
119
        }
115
120
 
120
125
 
121
126
static void add_url(const char *url)
122
127
{
123
 
        add_file(url);
 
128
        add_file(url, 0);
124
129
}
125
130
 
126
131
static void add_cdda(const char *url)
134
139
                int i;
135
140
                for (i = start_track; i <= end_track; i++) {
136
141
                        char *new_url = gen_cdda_url(disc_id, i, -1);
137
 
                        add_file(new_url);
 
142
                        add_file(new_url, 0);
138
143
                        free(new_url);
139
144
                }
140
145
        } else
141
 
                add_file(url);
 
146
                add_file(url, 0);
142
147
        free(disc_id);
143
148
}
144
149
 
234
239
                        if (S_ISDIR(ents[i]->mode)) {
235
240
                                add_dir(dir.path, root);
236
241
                        } else {
237
 
                                add_file(dir.path);
 
242
                                add_file(dir.path, 0);
238
243
                        }
239
244
                }
240
245
                free(ents[i]);
251
256
                add_url(line);
252
257
        } else {
253
258
                char *absolute = path_absolute_cwd(line, data);
254
 
                add_file(absolute);
 
259
                add_file(absolute, 0);
255
260
                free(absolute);
256
261
        }
 
262
 
257
263
        return 0;
258
264
}
259
265
 
294
300
                add_dir(jd->name, jd->name);
295
301
                break;
296
302
        case FILE_TYPE_FILE:
297
 
                add_file(jd->name);
 
303
                add_file(jd->name, jd->force);
298
304
                break;
299
305
        case FILE_TYPE_INVALID:
300
306
                break;
323
329
 
324
330
                /* stat follows symlinks, lstat does not */
325
331
                rc = stat(ti->filename, &s);
326
 
                if (rc || d->force || ti->mtime != s.st_mtime) {
 
332
                if (rc || d->force || ti->mtime != s.st_mtime || ti->duration == 0) {
 
333
                        int force = ti->duration == 0;
327
334
                        editable_lock();
328
335
                        lib_remove(ti);
329
336
                        editable_unlock();
332
339
                        cache_remove_ti(ti);
333
340
                        cache_unlock();
334
341
 
335
 
                        if (rc) {
 
342
                        if (!is_cue_url(ti->filename) && !is_http_url(ti->filename) && rc) {
336
343
                                d_print("removing dead file %s\n", ti->filename);
337
344
                        } else {
338
345
                                if (ti->mtime != s.st_mtime)
339
346
                                        d_print("mtime changed: %s\n", ti->filename);
340
 
                                cmus_add(lib_add_track, ti->filename, FILE_TYPE_FILE, JOB_TYPE_LIB);
 
347
                                cmus_add(lib_add_track, ti->filename, FILE_TYPE_FILE, JOB_TYPE_LIB, force);
341
348
                        }
342
349
                }
343
350
                track_info_unref(ti);