<commit_before><?php
require_once('db.inc.php');
require_once('functions.inc.php');

if (isset($argv) && isset($argv[1])){
	$fansub_to_fetch = $argv[1];
}
if (isset($argv) && isset($argv[2])){
	$force = $argv[2];
}

$lock_pointer = fopen($lock_file, "w+");

//We acquire a file lock to prevent two invocations at the same time.
//This could happen if a fansub requests a refresh via token just when a new periodic refresh is starting
if (flock($lock_pointer, LOCK_EX)) {
	$result = mysqli_query($db_connection, "SELECT f.*, (SELECT MAX(date) FROM news n WHERE n.fetcher_id=f.id) last_fetched_item_date FROM fetchers f LEFT JOIN fansubs fa ON f.fansub_id=fa.id WHERE ".(isset($fansub_to_fetch) ? "fansub_id='$fansub_to_fetch'":"f.fetch_type='periodic'")." ORDER BY fetch_type DESC, fa.name ASC, f.url ASC") or die(mysqli_error($db_connection));
	while ($row = mysqli_fetch_assoc($result)){
		echo "Fetching fetcher ".$row['fansub_id']."/".$row['id']."\n";
		fetch_fansub_fetcher($db_connection, $row['fansub_id'],$row['id'],$row['method'],$row['url'],(((isset($force) && $force) || $row['last_fetched_item_date']==NULL) ? '2000-01-01 00:00:00' : $row['last_fetched_item_date']));
		sleep(2);
	}

	mysqli_free_result($result);
	flock($lock_pointer, LOCK_UN);
} else {
	die("Couldn't get the lock!");
}

fclose($lock_pointer);

mysqli_close($db_connection);
?><commit_msg>Correctly fetch onetime feeds on first run<commit_after><?php
require_once('db.inc.php');
require_once('functions.inc.php');

if (isset($argv) && isset($argv[1])){
	$fansub_to_fetch = $argv[1];
}
if (isset($argv) && isset($argv[2])){
	$force = $argv[2];
}

$lock_pointer = fopen($lock_file, "w+");

//We acquire a file lock to prevent two invocations at the same time.
//This could happen if a fansub requests a refresh via token just when a new periodic refresh is starting
if (flock($lock_pointer, LOCK_EX)) {
	$result = mysqli_query($db_connection, "SELECT f.*, (SELECT MAX(date) FROM news n WHERE n.fetcher_id=f.id) last_fetched_item_date FROM fetchers f LEFT JOIN fansubs fa ON f.fansub_id=fa.id WHERE ".(isset($fansub_to_fetch) ? "fansub_id='$fansub_to_fetch' AND f.fetch_type NOT LIKE 'onetime%'":"f.fetch_type='periodic' OR (f.fetch_type LIKE 'onetime%' AND f.last_fetch_date IS NULL)")." ORDER BY fetch_type DESC, fa.name ASC, f.url ASC") or die(mysqli_error($db_connection));
	while ($row = mysqli_fetch_assoc($result)){
		echo "Fetching fetcher ".$row['fansub_id']."/".$row['id']."\n";
		fetch_fansub_fetcher($db_connection, $row['fansub_id'],$row['id'],$row['method'],$row['url'],(((isset($force) && $force) || $row['last_fetched_item_date']==NULL) ? '2000-01-01 00:00:00' : $row['last_fetched_item_date']));
		sleep(2);
	}

	mysqli_free_result($result);
	flock($lock_pointer, LOCK_UN);
} else {
	die("Couldn't get the lock!");
}

fclose($lock_pointer);

mysqli_close($db_connection);
?>
{'fraction_non_alphanumeric': 0.18654114365411437, 'fraction_numerical': 0.013249651324965132, 'mean_word_length': 6.650666666666667, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 5, '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': '3555477', 'n_tokens_mistral': 1142, 'n_tokens_neox': 1089, 'n_words': 239}