<commit_before><?php
require_once('help/DatabaseHelper.php');

function parse() {
    $dbHelper = new DatabaseHelper();

    switch($_GET['type']) {
        // get the count of several pages
        case 'get':
            $pages = json_decode($_GET['pages']);
            if (!is_array($pages)) {
                header("HTTP/1.1 400 Bad Request");
                return '';
            }
            foreach ($pages as $index => $page) {
                if (isset($page->url) && isset($page->domain)) {
                    $result = $dbHelper->query('page', [
                        'url' => $page->url,
                        'domain' => $page->domain,
                    ]);
                    if (is_null($result)) {
                        $page->count = 0;
                    } else {
                        $page->title = $result['title'];
                        $page->count = intval($result['count']);
                    }
                } else {
                    unset($pages[$index]);
                }
            }
            return json_encode($pages);

        // increase the count of a visited page
        case 'increment':
            $row = $dbHelper->query('page', [
                'url' => $_GET['url'],
                'domain' => $_GET['domain'],
            ]);
            if (isset($row)) {
                $count = ++$row['count'];
                $dbHelper->update('page', [ 'count' => $count ], [ 'id' => $row['id'] ]);
            } else {
                $dbHelper->insert('page', [
                    'url' => $_GET['url'],
                    'domain' => $_GET['domain'],
                    'title' => $_GET['title'],
                    'count' => 1
                ]);
                $row = [
                    'url' => $_GET['url'],
                    'domain' => $_GET['domain'],
                    'title' => $_GET['title'],
                    'count' => 1,
                ];
            }
            unset($row['id']);
            return json_encode($row);

        // get the pages which have been mostly visited<commit_msg>bug of increment fixed<commit_after><?php
require_once('help/DatabaseHelper.php');

function parse() {
    $dbHelper = new DatabaseHelper();

    switch($_GET['type']) {
        // get the count of several pages
        case 'get':
            $pages = json_decode($_GET['pages']);
            if (!is_array($pages)) {
                header("HTTP/1.1 400 Bad Request");
                return '';
            }
            foreach ($pages as $index => $page) {
                if (isset($page->url) && isset($page->domain)) {
                    $row = $dbHelper->query('page', [
                        'url' => $page->url,
                        'domain' => $page->domain,
                    ]);
                    if (is_null($row)) {
                        $page->count = 0;
                    } else {
                        $page->title = $row['title'];
                        $page->count = intval($row['count']);
                    }
                } else {
                    unset($pages[$index]);
                }
            }
            return json_encode($pages);

        // increase the count of a visited page
        case 'increment':
            $row = $dbHelper->query('page', [
                'url' => $_GET['url'],
                'domain' => $_GET['domain'],
            ]);
            $count = 1;
            if (isset($row)) {
                $count = ++$row['count'];
                $dbHelper->update('page', [ 'count' => $count ], [ 'id' => $row['id'] ]);
            } else {
                $dbHelper->insert('page', [
                    'url' => $_GET['url'],
                    'domain' => $_GET['domain'],
                    'title' => $_GET['title'],
                    'count' => 1
                ]);
            }
            return json_encode([
                'url' => $_GET['url'],
                'domain' => $_GET['domain'],
                'title' => $_GET['title'],
                'count' => $count,
            ]);

        // get the pages which have been mostly visited
{'fraction_non_alphanumeric': 0.16666666666666666, 'fraction_numerical': 0.003875968992248062, 'mean_word_length': 1.0970035551041137, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 55, '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': '6280531', 'n_tokens_mistral': 1080, 'n_tokens_neox': 1016, 'n_words': 214}