def timestamp_verifier(self): """ Return the time at which the data was last updated. If the value returned by the function is newer than the cache, the cache will be invalidated. @return: string-formatted time '%Y-%m-%d %H:%M:%S' """ return max(get_table_update_time('collectionname'), get_table_update_time('collection_collection'))
def _check_table_update_time(self, tablename): """Helper function to check update time of TABLENAME.""" # detect MySQL version number: res = dbquery.run_sql("SELECT VERSION()") mysql_server_version = res[0][0] if mysql_server_version.startswith("5."): # MySQL-5 provides INFORMATION_SCHEMA: query = """SELECT UPDATE_TIME FROM INFORMATION_SCHEMA.TABLES WHERE table_name='%s' AND table_schema='%s'""" % ( tablename, dbquery.CFG_DATABASE_NAME, ) tablename_update_time = str(dbquery.run_sql(query)[0][0]) elif mysql_server_version.startswith("4.1"): # MySQL-4.1 has it on 12th position: query = """SHOW TABLE STATUS LIKE '%s'""" % tablename tablename_update_time = str(dbquery.run_sql(query)[0][12]) elif mysql_server_version.startswith("4.0"): # MySQL-4.0 has it on 11th position: query = """SHOW TABLE STATUS LIKE '%s'""" % tablename tablename_update_time = str(dbquery.run_sql(query)[0][11]) else: tablename_update_time = "MYSQL SERVER VERSION NOT DETECTED" # compare it with the one detected by the function: self.assertEqual(tablename_update_time, dbquery.get_table_update_time(tablename))
def timestamp_verifier(self): """ Return the time at which the data was last updated. If the value returned by the function is newer than the cache, the cache will be invalidated. @return: string-formatted time '%Y-%m-%d %H:%M:%S' """ # This is an approximation... return get_table_update_time('knwKBRVAL')
def get_database_last_updated_timestamp(): """Return last updated timestamp for collection-related and record-related database tables. """ database_tables_timestamps = [] database_tables_timestamps.append(get_table_update_time('bibrec')) database_tables_timestamps.append(get_table_update_time('bibfmt')) database_tables_timestamps.append(get_table_update_time('idxWORD%')) database_tables_timestamps.append(get_table_update_time('collection%')) database_tables_timestamps.append(get_table_update_time('portalbox')) database_tables_timestamps.append(get_table_update_time('field%')) database_tables_timestamps.append(get_table_update_time('format%')) database_tables_timestamps.append(get_table_update_time('rnkMETHODNAME')) return max(database_tables_timestamps)
def get_database_last_updated_timestamp(): """Return last updated timestamp for collection-related and record-related database tables. """ database_tables_timestamps = [] database_tables_timestamps.append(get_table_update_time('bibrec')) database_tables_timestamps.append(get_table_update_time('bibfmt')) try: database_tables_timestamps.append(get_table_update_time('idxWORD%')) except ValueError: # There are no indexes in the database. That's OK. pass database_tables_timestamps.append(get_table_update_time('collection%')) database_tables_timestamps.append(get_table_update_time('portalbox')) database_tables_timestamps.append(get_table_update_time('field%')) database_tables_timestamps.append(get_table_update_time('format%')) database_tables_timestamps.append(get_table_update_time('rnkMETHODNAME')) database_tables_timestamps.append(get_table_update_time('accROLE_accACTION_accARGUMENT')) return max(database_tables_timestamps)
def get_database_last_updated_timestamp(): """Return last updated timestamp for collection-related and record-related database tables. """ database_tables_timestamps = [] database_tables_timestamps.append(get_table_update_time("bibrec")) database_tables_timestamps.append(get_table_update_time("bibfmt")) try: database_tables_timestamps.append(get_table_update_time("idxWORD%")) except ValueError: # There are no indexes in the database. That's OK. pass database_tables_timestamps.append(get_table_update_time("collection%")) database_tables_timestamps.append(get_table_update_time("portalbox")) database_tables_timestamps.append(get_table_update_time("field%")) database_tables_timestamps.append(get_table_update_time("format%")) database_tables_timestamps.append(get_table_update_time("rnkMETHODNAME")) database_tables_timestamps.append(get_table_update_time("accROLE_accACTION_accARGUMENT", run_on_slave=True)) return max(database_tables_timestamps)
def calculate_index_term_count(config): """Calculate the weight of a record set based on number of enries of a tag from the record in another index...useful for authority files""" records = [] if config.has_section("index_term_count"): index = config.get("index_term_count", "index_table_name") tag = config.get("index_term_count", "index_term_value_from_tag") # check against possible SQL injection: dummy = get_table_update_time(index) tag = wash_table_column_name(tag) else: raise Exception("Config file " + config + " does not have index_term_count section") return () task_sleep_now_if_required(can_stop_too=True) write_message("......Processing all records") query = "SELECT id_bibrec, value FROM bib%sx, bibrec_bib%sx WHERE tag=%%s AND id_bibxxx=id" % \ (tag[0:2], tag[0:2]) # we checked that tag is safe records = list(run_sql(query, (tag, ))) write_message("Number of records found with the necessary tags: %s" % len(records)) rnkset = {} for key, value in records: hits = 0 if len(value): query = "SELECT hitlist from %s where term = %%s" % index # we checked that index is a table row = run_sql(query, (value, )) if row and row[0] and row[0][0]: #has to be prepared for corrupted data! try: hits = len(intbitset(row[0][0])) except: hits = 0 rnkset[key] = hits write_message("Number of records available in rank method: %s" % len(rnkset)) return rnkset
def calculate_index_term_count(config): """Calculate the weight of a record set based on number of enries of a tag from the record in another index...useful for authority files""" records = [] if config.has_section("index_term_count"): index = config.get("index_term_count","index_table_name") tag = config.get("index_term_count","index_term_value_from_tag") # check against possible SQL injection: dummy = get_table_update_time(index) tag = wash_table_column_name(tag) else: raise Exception("Config file " + config + " does not have index_term_count section") return() task_sleep_now_if_required(can_stop_too=True) write_message("......Processing all records") query = "SELECT id_bibrec, value FROM bib%sx, bibrec_bib%sx WHERE tag=%%s AND id_bibxxx=id" % \ (tag[0:2], tag[0:2]) # we checked that tag is safe records = list(run_sql(query, (tag,))) write_message("Number of records found with the necessary tags: %s" % len(records)) rnkset = {} for key, value in records: hits = 0 if len(value): query = "SELECT hitlist from %s where term = %%s" % index # we checked that index is a table row = run_sql(query, (value,)) if row and row[0] and row[0][0]: #has to be prepared for corrupted data! try: hits = len(intbitset(row[0][0])) except: hits = 0 rnkset[key] = hits write_message("Number of records available in rank method: %s" % len(rnkset)) return rnkset
def _check_table_update_time(self, tablename): """Helper function to check update time of TABLENAME.""" # detect MySQL version number: res = dbquery.run_sql("SELECT VERSION()") mysql_server_version = res[0][0] if mysql_server_version.startswith("5."): # MySQL-5 provides INFORMATION_SCHEMA: query = """SELECT UPDATE_TIME FROM INFORMATION_SCHEMA.TABLES WHERE table_name='%s'""" % tablename tablename_update_time = str(dbquery.run_sql(query)[0][0]) elif mysql_server_version.startswith("4.1"): # MySQL-4.1 has it on 12th position: query = """SHOW TABLE STATUS LIKE '%s'""" % tablename tablename_update_time = str(dbquery.run_sql(query)[0][12]) elif mysql_server_version.startswith("4.0"): # MySQL-4.0 has it on 11th position: query = """SHOW TABLE STATUS LIKE '%s'""" % tablename tablename_update_time = str(dbquery.run_sql(query)[0][11]) else: tablename_update_time = "MYSQL SERVER VERSION NOT DETECTED" # compare it with the one detected by the function: self.assertEqual(tablename_update_time, dbquery.get_table_update_time(tablename))
def timestamp_verifier(): """The standard timestamp verifier is looking at affected tables time stamp.""" return max([get_table_update_time(table) for table in self.affected_tables])
def timestamp_verifier(): """The standard timestamp verifier is looking at affected tables time stamp.""" return max([ get_table_update_time(table) for table in self.affected_tables ])
def timestamp_verifier(): return get_table_update_time("rnkCITATIONDATA")