def do_reindex(with_reindex_snapshots=False): """Update the full text search index.""" indexer = get_indexer() indexed_models = { m.__name__: m for m in all_models.all_models if issubclass(m, mixin.Indexed) and m.REQUIRED_GLOBAL_REINDEX } people_query = db.session.query(all_models.Person.id, all_models.Person.name, all_models.Person.email) indexer.cache["people_map"] = {p.id: (p.name, p.email) for p in people_query} indexer.cache["ac_role_map"] = dict(db.session.query( all_models.AccessControlRole.id, all_models.AccessControlRole.name, )) for model_name in sorted(indexed_models.keys()): logger.info("Updating index for: %s", model_name) with benchmark("Create records for %s" % model_name): model = indexed_models[model_name] ids = [obj.id for obj in model.query] ids_count = len(ids) handled_ids = 0 for ids_chunk in utils.list_chunks(ids, chunk_size=REINDEX_CHUNK_SIZE): handled_ids += len(ids_chunk) logger.info("%s: %s / %s", model.__name__, handled_ids, ids_count) model.bulk_record_update_for(ids_chunk) db.session.commit() if with_reindex_snapshots: logger.info("Updating index for: %s", "Snapshot") with benchmark("Create records for %s" % "Snapshot"): snapshot_indexer.reindex() indexer.invalidate_cache()
def do_reindex(with_reindex_snapshots=False, delete=False): """Update the full text search index.""" indexer = fulltext.get_indexer() indexed_models = { m.__name__: m for m in models.all_models.all_models if issubclass(m, mixin.Indexed) and m.REQUIRED_GLOBAL_REINDEX } people_query = db.session.query(models.all_models.Person.id, models.all_models.Person.name, models.all_models.Person.email) indexer.cache["people_map"] = { p.id: (p.name, p.email) for p in people_query } indexer.cache["ac_role_map"] = dict( db.session.query( models.all_models.AccessControlRole.id, models.all_models.AccessControlRole.name, )) _remove_dead_reindex_objects(indexed_models) for model_name in sorted(indexed_models.keys()): if delete: with benchmark("Deleting records for %s" % model_name): pass logger.info("Updating index for: %s", model_name) with benchmark("Create records for %s" % model_name): model = indexed_models[model_name] ids = [id_[0] for id_ in db.session.query(model.id)] ids_count = len(ids) handled_ids = 0 ids_chunks = ggrc_utils.list_chunks(ids, chunk_size=REINDEX_CHUNK_SIZE) for ids_chunk in ids_chunks: handled_ids += len(ids_chunk) logger.info("%s: %s / %s", model.__name__, handled_ids, ids_count) model.bulk_record_update_for(ids_chunk) db.session.plain_commit() if with_reindex_snapshots: logger.info("Updating index for: %s", "Snapshot") with benchmark("Create records for %s" % "Snapshot"): snapshot_indexer.reindex() indexer.invalidate_cache()
def reindex_snapshots(_): """Web hook to update the full text search index.""" logger.info("Updating index for: %s", "Snapshot") with benchmark("Create records for %s" % "Snapshot"): snapshot_indexer.reindex() return app.make_response(("success", 200, [("Content-Type", "text/html")]))