async def _init_stdlib(cluster, conn, testmode): in_dev_mode = devmode.is_in_dev_mode() cache_hit = False sql_text = None if in_dev_mode: schema_cache = 'backend-stdschema.pickle' script_cache = 'backend-stdinitsql.pickle' testmode_flag = 'backend-stdtestmode.pickle' src_hash = devmode.hash_dirs(CACHE_SRC_DIRS) cached_testmode = devmode.read_dev_mode_cache(src_hash, testmode_flag) if cached_testmode is not None and cached_testmode == testmode: sql_text = devmode.read_dev_mode_cache(src_hash, script_cache) if sql_text is not None: schema = devmode.read_dev_mode_cache(src_hash, schema_cache) if sql_text is None or schema is None: schema, sql_text, new_types = await _make_stdlib(testmode) else: cache_hit = True await _execute_ddl(conn, sql_text) if not cache_hit: typemap = await conn.fetch( ''' SELECT id, backend_id FROM edgedb.type WHERE id = any($1::uuid[]) ''', new_types) for tid, backend_tid in typemap: t = schema.get_by_id(tid) schema = t.set_field_value(schema, 'backend_id', backend_tid) if not cache_hit and in_dev_mode: devmode.write_dev_mode_cache(schema, src_hash, schema_cache) devmode.write_dev_mode_cache(sql_text, src_hash, script_cache) devmode.write_dev_mode_cache(testmode, src_hash, testmode_flag) await _store_static_bin_cache( cluster, 'stdschema', pickle.dumps(schema, protocol=pickle.HIGHEST_PROTOCOL), ) await metaschema.generate_views(conn, schema) await metaschema.generate_support_views(conn, schema) return schema
async def _init_stdlib(cluster, conn, testmode): data_dir = pathlib.Path(cluster.get_data_dir()) in_dev_mode = devmode.is_in_dev_mode() cache_hit = False sql_text = None cluster_schema_cache = data_dir / 'stdschema.pickle' if in_dev_mode: schema_cache = 'backend-stdschema.pickle' script_cache = 'backend-stdinitsql.pickle' testmode_flag = 'backend-stdtestmode.pickle' src_hash = devmode.hash_dirs(CACHE_SRC_DIRS) cached_testmode = devmode.read_dev_mode_cache(src_hash, testmode_flag) if cached_testmode is not None and cached_testmode == testmode: sql_text = devmode.read_dev_mode_cache(src_hash, script_cache) if sql_text is not None: schema = devmode.read_dev_mode_cache(src_hash, schema_cache) if sql_text is None or schema is None: schema, sql_text = await _make_stdlib(testmode) else: cache_hit = True await _execute_ddl(conn, sql_text) if not cache_hit and in_dev_mode: devmode.write_dev_mode_cache(schema, src_hash, schema_cache) devmode.write_dev_mode_cache(sql_text, src_hash, script_cache) devmode.write_dev_mode_cache(testmode, src_hash, testmode_flag) with open(cluster_schema_cache, 'wb') as f: pickle.dump(schema, file=f, protocol=pickle.HIGHEST_PROTOCOL) await metaschema.generate_views(conn, schema) await metaschema.generate_support_views(conn, schema) return schema
def load_std_schema() -> s_schema.Schema: std_dirs_hash = devmode.hash_dirs(CACHE_SRC_DIRS) schema = None if devmode.is_in_dev_mode(): schema = devmode.read_dev_mode_cache( std_dirs_hash, 'transient-stdschema.pickle') if schema is None: schema = s_schema.Schema() for modname in s_schema.STD_LIB: schema = load_std_module(schema, modname) if devmode.is_in_dev_mode(): devmode.write_dev_mode_cache( schema, std_dirs_hash, 'transient-stdschema.pickle') return schema
def _load_std_schema(): global _std_schema if _std_schema is None: std_dirs_hash = devmode.hash_dirs(s_std.CACHE_SRC_DIRS) schema = None if devmode.is_in_dev_mode(): schema = devmode.read_dev_mode_cache( std_dirs_hash, 'transient-stdschema.pickle') if schema is None: schema = s_schema.Schema() for modname in s_schema.STD_LIB + ('stdgraphql',): schema = s_std.load_std_module(schema, modname) if devmode.is_in_dev_mode(): devmode.write_dev_mode_cache( schema, std_dirs_hash, 'transient-stdschema.pickle') _std_schema = schema return _std_schema