<commit_before>/*
 * Copyright (C) 2008, Nokia <<EMAIL>>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA  02110-1301, USA.
 */

using Tracker;
using Tracker.Sparql;

const int max_signals = 1000;
// const int max_signals = 10000;
const string title_data = "title";

struct Event {
	int graph_id;
	int subject_id;
	int pred_id;
	int object_id;
}

[DBus (name = "org.freedesktop.Tracker1.Resources")]
private interface Resources : GLib.Object {
	[DBus (name = "GraphUpdated")]
	public signal void graph_updated (string class_name, Event[] deletes, Event[] inserts);

	[DBus (name = "BatchSparqlUpdate")]
	public abstract async void batch_sparql_update_async (string query) throws Sparql.Error, DBus.Error;

	[DBus (name = "SparqlUpdate")]
	public abstract async void sparql_update_async (string query) throws Sparql.Error, DBus.Error;

}

[DBus (name = "org.freedesktop.Tracker1.Resources.Class")]
private interface ResourcesClass : GLib.Object {
	[DBus (name = "SubjectsAdded")]
	public signal void subjects_added (string [] subjects);
	[DBus (name = "SubjectsChanged")]
	public signal void subjects_changed (string [] subjects, string [] preds);
}

public class TestApp {
	static DBus.Connection dbus_connection;
	static Resources resources_object;
	static ResourcesClass class_object;
	MainLoop loop;
	bool initialized = false;
	Sparql.Connection con;
	int count = 0;
	GLib.Timer t;

	public TestApp ()
	requires (!initialized) {
		try {
			con = Tracker.Sparql.Connection.get();
			dbus_connection = DBus.Bus.get (DBus.BusType.SESSION);
			resources_object = (Resources) dbus_connection.get_object ("org.freedesktop.Tracker1",
			                                                           "/org/freedesktop/Tracker1/Resources",
			                                                           "org.freedesktop.Tracker1.Resources");

			class_object = (ResourcesClass) dbus_connection.get_object ("org.freedesktop.Tracker1",
		                                                                "/org/freedesktop/Tracker1/Resources/Classes/nmm/MusicPiece",
		                                                                "org.freedesktop.Tracker1.Resources.Class");

			class_object.subjects_added.connect (on_subjects_added);
			class_object.subjects_changed.connect (on_subjects_changed);

			resources_object.graph_updated.connect (on_graph_updated_received);
			t = new GLib.Timer ();
			
		} catch (GLib.Error e) {
			warning ("Could not connect to D-Bus service: %s", e.message);
			initialized = false;
			return;
		}
		initialized = true;
	}

	private void on_subjects_changed (string [] subjects, string [] preds) {
		foreach (string s in subjects)
			count++;

		//if (count == 20002)
			print ("Old class signal count=%d time=%lf\n", count, t.elapsed ());
	}

	private void on_subjects_added (string [] subjects) {
		foreach (string s in subjects)
			count++;

		//if (count == 20002)
			print ("Old class signal count=%d time=%lf\n", count, t.elapsed ());
	}

	private void on_graph_updated_received (string class_name, Event[] deletes, Event[] inserts) {
		foreach (Event insert in inserts)
			count++;
		//if (count == 20002)
			print ("New class signal count=%d time=%lf\n", count, t.elapsed ());
	}

	private void insert_data () {
		int i;
//		for (i = 0; i <= max_signals; i++) {
//			string upqry = "DELETE { <%d> a rdfs:Resource }".printf(i);
//			resources_object.sparql_update_async (upqry);
//		}

		t.start();
		for (i = 0; i <= max_signals; i++) {
			string upqry = "INSERT { <%d> a nmm:MusicPiece ; nie:title '%s %d' }".printf(i, title_data, i);<commit_msg>functional-tests:ipc: Cleanup test for signal enhancement for batch_update<commit_after>/*
 * Copyright (C) 2008, Nokia <<EMAIL>>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA  02110-1301, USA.
 */

using Tracker;
using Tracker.Sparql;

const int max_signals = 1000;
const string title_data = "title";

struct Event {
	int graph_id;
	int subject_id;
	int pred_id;
	int object_id;
}

[DBus (name = "org.freedesktop.Tracker1.Resources")]
private interface Resources : GLib.Object {
	[DBus (name = "GraphUpdated")]
	public signal void graph_updated (string class_name, Event[] deletes, Event[] inserts);
	[DBus (name = "BatchSparqlUpdate")]
	public abstract async void batch_sparql_update_async (string query) throws Sparql.Error, DBus.Error;
	[DBus (name = "SparqlUpdate")]
	public abstract async void sparql_update_async (string query) throws Sparql.Error, DBus.Error;
}

public class TestApp {
	static DBus.Connection dbus_connection;
	static Resources resources_object;
	MainLoop loop;
	bool initialized = false;
	Sparql.Connection con;
	int count = 0;
	GLib.Timer t;

	public TestApp ()
	requires (!initialized) {
		try {
			con = Tracker.Sparql.Connection.get();
			dbus_connection = DBus.Bus.get (DBus.BusType.SESSION);
			resources_object = (Resources) dbus_connection.get_object ("org.freedesktop.Tracker1",
			                                                           "/org/freedesktop/Tracker1/Resources",
			                                                           "org.freedesktop.Tracker1.Resources");


			resources_object.graph_updated.connect (on_graph_updated_received);
			t = new GLib.Timer ();
			
		} catch (GLib.Error e) {
			warning ("Could not connect to D-Bus service: %s", e.message);
			initialized = false;
			return;
		}
		initialized = true;
	}

	private void on_graph_updated_received (string class_name, Event[] deletes, Event[] inserts) {
		foreach (Event insert in inserts)
			count++;
		print ("New class signal count=%d time=%lf\n", count, t.elapsed ());
	}

	private void insert_data () {
		int i;
		for (i = 0; i <= max_signals; i++) {
			string upqry = "DELETE { <%d> a rdfs:Resource }".printf(i);
			resources_object.sparql_update_async (upqry);
		}

		t.start();
		for (i = 0; i <= max_signals; i++) {
			string upqry = "INSERT { <%d> a nmm:MusicPiece ; nie:title '%s %d' }".printf(i, title_data, i);
{'fraction_non_alphanumeric': 0.10877337733773378, 'fraction_numerical': 0.010726072607260726, 'mean_word_length': 3.3524835427887494, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3436721', 'n_tokens_mistral': 2387, 'n_tokens_neox': 2170, 'n_words': 719}