X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;ds=sidebyside;f=daklib%2Fdatabase.py;h=cad427ac07c682b5994f0bf26cd12eaedbd0e9aa;hb=0b77fe45647e0342dca44d574225033b331a0ce0;hp=3a6c9aec341c8c991f0f9ec7f50bc67c77b9ec00;hpb=7a7563b8e19f99783505669ba603ef2d534c6603;p=dak.git diff --git a/daklib/database.py b/daklib/database.py index 3a6c9aec..cad427ac 100755 --- a/daklib/database.py +++ b/daklib/database.py @@ -41,6 +41,7 @@ maintainer_cache = {} fingerprint_id_cache = {} queue_id_cache = {} uid_id_cache = {} +suite_version_cache = {} ################################################################################ @@ -223,25 +224,26 @@ def get_source_id (source, version): return source_id -def get_testing_version(source): - global testing_version_cache +def get_suite_version(source, suite): + global suite_version_cache + cache_key = "%s_%s" % (source, suite) - if testing_version_cache.has_key(source): - return testing_version_cache[source] + if suite_version_cache.has_key(cache_key): + return suite_version_cache[cache_key] - q = Upload.projectB.query(""" + q = projectB.query(""" SELECT s.version FROM source s, suite su, src_associations sa WHERE sa.source=s.id AND sa.suite=su.id - AND su.suite_name='testing' + AND su.suite_name='%s' AND s.source='%s'""" - % (source)) + % (suite, source)) if not q.getresult(): return None version = q.getresult()[0][0] - testing_version_cache[source] = version + suite_version_cache[cache_key] = version return version @@ -315,7 +317,7 @@ def get_or_set_fingerprint_id (fingerprint): ################################################################################ -def get_files_id (filename, size, md5sum, location_id): +def get_files_id (filename, size, md5sum, sha1sum, sha256sum location_id): global files_id_cache cache_key = "%s_%d" % (filename, location_id) @@ -324,7 +326,7 @@ def get_files_id (filename, size, md5sum, location_id): return files_id_cache[cache_key] size = int(size) - q = projectB.query("SELECT id, size, md5sum FROM files WHERE filename = '%s' AND location = %d" % (filename, location_id)) + q = projectB.query("SELECT id, size, md5sum, sha1sum, sha256sum FROM files WHERE filename = '%s' AND location = %d" % (filename, location_id)) ql = q.getresult() if ql: if len(ql) != 1: @@ -332,7 +334,9 @@ def get_files_id (filename, size, md5sum, location_id): ql = ql[0] orig_size = int(ql[1]) orig_md5sum = ql[2] - if orig_size != size or orig_md5sum != md5sum: + orig_sha1sum = ql[3] + orig_sha256sum = ql[4] + if orig_size != size or orig_md5sum != md5sum or orig_sha1sum != sha1sum or orig_sha256sum != sha256sum: return -2 files_id_cache[cache_key] = ql[0] return files_id_cache[cache_key] @@ -358,12 +362,12 @@ def get_or_set_queue_id (queue): ################################################################################ -def set_files_id (filename, size, md5sum, location_id): +def set_files_id (filename, size, md5sum, sha1sum, sha256sum, location_id): global files_id_cache - projectB.query("INSERT INTO files (filename, size, md5sum, location) VALUES ('%s', %d, '%s', %d)" % (filename, long(size), md5sum, location_id)) + projectB.query("INSERT INTO files (filename, size, md5sum, sha1sum, sha256sum, location) VALUES ('%s', %d, '%s', %d)" % (filename, long(size), md5sum, sha1sum, sha256sum location_id)) - return get_files_id (filename, size, md5sum, location_id) + return get_files_id (filename, size, md5sum, sha1sum, sha256sum, location_id) ### currval has issues with postgresql 7.1.3 when the table is big ### it was taking ~3 seconds to return on auric which is very Not