<commit_before>/*
 * This file is part of Kotaka, a mud library for DGD
 * http://github.com/shentino/kotaka
 *
 * Copyright (C) 2010, 2012, 2013, 2014, 2015  <NAME>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program 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 Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
#include <kotaka/log.h>
#include <kotaka/paths/system.h>
#include <kotaka/paths/channel.h>
#include <kotaka/paths/bigstruct.h>
#include <kotaka/privilege.h>
#include <status.h>
#include <type.h>

inherit SECOND_AUTO;

object queue;
object patch;
int qlen;

private void destruct_queue()
{
	int sz;
	object *turkeys;

	turkeys = ({ });

	if (queue) {
		turkeys += ({ queue });
		queue = nil;
	}

	if (patch) {
		turkeys  += ({ patch });
		patch = nil;
	}

	for (sz = sizeof(turkeys) - 1; sz >= 0; --sz)
	{
		destruct_object(turkeys[sz]);
	}
}

static void create()
{
}

static void destruct()
{
	destruct_queue();
}

void call_touch(object obj)
{
	ACCESS_CHECK(SYSTEM());

	if (!queue || queue->empty()) {
		queue = clone_object(BIGSTRUCT_DEQUE_OBJ);
		queue->claim();
		call_out("touch_tick", 0);
	}

	qlen++;

	queue->push_back(obj);

	::call_touch(obj);
}

private void queue_patches(object obj, string *patches)
{
	string name;
	int oindex;
	string *old;

	name = object_name(obj);

	if (!sscanf(name, "%*s#%d", oindex)) {
		oindex = status(obj, O_INDEX);
	}

	old = patch->query_element(oindex);

	if (!old) {
		old = ({ });
	}

	old |= patches;

	patch->set_element(oindex, old);
}

void touch_scan_otable(string path, int sz, string *patches)
{
	int ticks;

	ACCESS_CHECK(previous_program() == SUSPENDD);

	ticks = status(ST_TICKS);

	while (sz >= 0 && status(ST_TICKS) > 20000 && ticks - status(ST_TICKS) < 100000) {
		object obj;

		if (sz % 10000 == 0) {
			LOGD->post_message("debug", LOG_DEBUG, "TouchD: Scanning object table for " + path + ", currently at slot " + sz);
		}

		obj = find_object(path + "#" + sz);

		if (obj) {
			if (patches) {
				queue_patches(obj, patches);
			}

			call_touch(obj);
		}

		sz--;
	}

	if (sz >= 0) {
		SUSPENDD->queue_work("touch_scan_otable", path, sz, patches);
	} else {
		LOGD->post_message("debug", LOG_DEBUG, "TouchD: Finished object table scan for " + path);
	}
}

void touch_all(string path, varargs string *patches)
{
	ACCESS_CHECK(SYSTEM());

	rlimits(0; -1) {
		object obj;

		obj = find_object(path);

		if (patches) {
			queue_patches(obj, patches);
		}

		call_touch(find_object(path));

		if (!sscanf(path, "%*s" + CLONABLE_SUBDIR)) {<commit_msg>Don't complicate things, just do touchd's work one item at a time.  Checking tick counts should only be done as a diagnostic anyway.<commit_after>/*
 * This file is part of Kotaka, a mud library for DGD
 * http://github.com/shentino/kotaka
 *
 * Copyright (C) 2010, 2012, 2013, 2014, 2015  <NAME>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program 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 Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
#include <kotaka/log.h>
#include <kotaka/paths/system.h>
#include <kotaka/paths/channel.h>
#include <kotaka/paths/bigstruct.h>
#include <kotaka/privilege.h>
#include <status.h>
#include <type.h>

inherit SECOND_AUTO;

object queue;
object patch;
int qlen;

private void destruct_queue()
{
	int sz;
	object *turkeys;

	turkeys = ({ });

	if (queue) {
		turkeys += ({ queue });
		queue = nil;
	}

	if (patch) {
		turkeys  += ({ patch });
		patch = nil;
	}

	for (sz = sizeof(turkeys) - 1; sz >= 0; --sz)
	{
		destruct_object(turkeys[sz]);
	}
}

static void create()
{
}

static void destruct()
{
	destruct_queue();
}

void call_touch(object obj)
{
	ACCESS_CHECK(SYSTEM());

	if (!queue || queue->empty()) {
		queue = clone_object(BIGSTRUCT_DEQUE_OBJ);
		queue->claim();
		call_out("touch_tick", 0);
	}

	qlen++;

	queue->push_back(obj);

	::call_touch(obj);
}

private void queue_patches(object obj, string *patches)
{
	string name;
	int oindex;
	string *old;

	name = object_name(obj);

	if (!sscanf(name, "%*s#%d", oindex)) {
		oindex = status(obj, O_INDEX);
	}

	old = patch->query_element(oindex);

	if (!old) {
		old = ({ });
	}

	old |= patches;

	patch->set_element(oindex, old);
}

void touch_scan_otable(string path, int sz, string *patches)
{
	object obj;

	ACCESS_CHECK(previous_program() == SUSPENDD);

	if (sz % 10000 == 0) {
		LOGD->post_message("debug", LOG_DEBUG, "TouchD: Scanning object table for " + path + ", currently at slot " + sz);
	}

	obj = find_object(path + "#" + sz);

	if (obj) {
		if (patches) {
			queue_patches(obj, patches);
		}

		call_touch(obj);
	}

	sz--;

	if (sz >= 0) {
		SUSPENDD->queue_work("touch_scan_otable", path, sz, patches);
	} else {
		LOGD->post_message("debug", LOG_DEBUG, "TouchD: Finished object table scan for " + path);
	}
}

void touch_all(string path, varargs string *patches)
{
	ACCESS_CHECK(SYSTEM());

	rlimits(0; -1) {
		object obj;

		obj = find_object(path);

		if (patches) {
			queue_patches(obj, patches);
		}

		call_touch(find_object(path));

		if (!sscanf(path, "%*s" + CLONABLE_SUBDIR)) {
{'fraction_non_alphanumeric': 0.14328014476065143, 'fraction_numerical': 0.01283105773975983, 'mean_word_length': 3.840764331210191, 'pattern_counts': {'":': 0, '<': 22, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '788877', 'n_tokens_mistral': 2369, 'n_tokens_neox': 2149, 'n_words': 638}