<commit_before>#include "OldDatabaseBackend.h"
#include "DBBackendFactory.h"
#include "DatabaseServer.h"

#include "core/global.h"
#include "util/DatagramIterator.h"
#include "dclass/value/format.h"
#include "dclass/value/parse.h"

#include <yaml-cpp/yaml.h>
#include <fstream> // std::ifstream
#include <list>    // std::list

using dclass::Class;
using dclass::Field;
using namespace std;

static ConfigVariable<string> foldername("foldername", "yaml_db", db_backend_config);

class YAMLDatabase : public OldDatabaseBackend
{
	private:
		doid_t m_next_id;
		list<doid_t> m_free_ids;
		string m_foldername;
		LogCategory *m_log;

		inline string filename(doid_t do_id)
		{
			stringstream filename;
			filename << m_foldername << "/" << do_id << ".yaml";
			return filename.str();
		}

		inline bool load(doid_t do_id, YAML::Node &document)
		{
			ifstream stream(filename(do_id));
			document = YAML::Load(stream);
			if(!document.IsDefined() || document.IsNull())
			{<commit_msg>YAMLDatabase: The load function is too long to make sense inlined.<commit_after>#include "OldDatabaseBackend.h"
#include "DBBackendFactory.h"
#include "DatabaseServer.h"

#include "core/global.h"
#include "util/DatagramIterator.h"
#include "dclass/value/format.h"
#include "dclass/value/parse.h"

#include <yaml-cpp/yaml.h>
#include <fstream> // std::ifstream
#include <list>    // std::list

using dclass::Class;
using dclass::Field;
using namespace std;

static ConfigVariable<string> foldername("foldername", "yaml_db", db_backend_config);

class YAMLDatabase : public OldDatabaseBackend
{
	private:
		doid_t m_next_id;
		list<doid_t> m_free_ids;
		string m_foldername;
		LogCategory *m_log;

		inline string filename(doid_t do_id)
		{
			stringstream filename;
			filename << m_foldername << "/" << do_id << ".yaml";
			return filename.str();
		}

		bool load(doid_t do_id, YAML::Node &document)
		{
			ifstream stream(filename(do_id));
			document = YAML::Load(stream);
			if(!document.IsDefined() || document.IsNull())
			{
{'fraction_non_alphanumeric': 0.13916500994035785, 'fraction_numerical': 0.0, 'mean_word_length': 5.081570996978852, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5143975', 'n_tokens_mistral': 759, 'n_tokens_neox': 715, 'n_words': 151}