<commit_before><?php
/**
 * This class will sync a users hashtags to their psuedo id
 * to allow for analytics to build privacy respecting recommendations
 */
namespace Minds\Core\Hashtags\User;

use Cassandra\Varint;
use Cassandra\Timestamp;
use Minds\Common\Repository\Response;
use Minds\Common\PseudonymousIdentifier;
use Minds\Core\Data\Cassandra\Client;
use Minds\Core\Data\Cassandra\Prepared\Custom;
use Minds\Core\Di\Di;
use Minds\Core\Hashtags\HashtagEntity;

class PseudoHashtags
{
    /** @var Client */
    protected $db;

    /** @var PseudonymousIdentifier */
    protected $pseudoId;

    public function __construct($db = null, $pseudoId = null)
    {
        $this->db = $db ?: Di::_()->get('Database\Cassandra\Cql');
        $this->pseuodId = $pseudoId ?? new PseudonymousIdentifier();
    }

    /**
     * @param HashtagEntity[] $hashtags
     * @return bool
     */
    public function syncTags(array $hashtags): bool
    {
        $cql = "INSERT INTO pseduo_user_hashtags (pseudo_id, hashtag) VALUES (?, ?)";
    
        foreach ($hashtags as $hashtag) {
            try {
                $params = [
                    $this->pseuodId->getId(),
                    (string) $hashtag->getHashtag()
                ];

                $prepared = new Custom();
                $prepared->query($cql, $params);

                $this->db->request($prepared, true);
            } catch (\Exception $e) {
                error_log(static::class . '::add() CQL Exception ' . $e->getMessage());
                return false;
            }
        }

        return true;
    }

    /**
     * @param HashtagEntity[] $hashtags
     * @return bool
     * @throws \Exception
     */
    public function addTags(array $hashtags): bool
    {
        return $this->syncTags($hashtags);
    }

    /**
     * @param HashtagEntity[] $hashtags
     * @return bool
     * @throws \Exception
     */
    public function removeTags(array $hashtags): bool
    {
        $cql = "DELETE FROM pseduo_user_hashtags WHERE pseudo_id = ? AND hashtag = ?";
    
        foreach ($hashtags as $hashtag) {
            try {
                $params = [
                    $this->pseuodId->getId(),
                    (string) $hashtag->getHashtag()<commit_msg>(fix): static analytics due to miss spelling of variable<commit_after><?php
/**
 * This class will sync a users hashtags to their psuedo id
 * to allow for analytics to build privacy respecting recommendations
 */
namespace Minds\Core\Hashtags\User;

use Cassandra\Varint;
use Cassandra\Timestamp;
use Minds\Common\Repository\Response;
use Minds\Common\PseudonymousIdentifier;
use Minds\Core\Data\Cassandra\Client;
use Minds\Core\Data\Cassandra\Prepared\Custom;
use Minds\Core\Di\Di;
use Minds\Core\Hashtags\HashtagEntity;

class PseudoHashtags
{
    /** @var Client */
    protected $db;

    /** @var PseudonymousIdentifier */
    protected $pseudoId;

    public function __construct($db = null, $pseudoId = null)
    {
        $this->db = $db ?: Di::_()->get('Database\Cassandra\Cql');
        $this->pseudoId = $pseudoId ?? new PseudonymousIdentifier();
    }

    /**
     * @param HashtagEntity[] $hashtags
     * @return bool
     */
    public function syncTags(array $hashtags): bool
    {
        $cql = "INSERT INTO pseduo_user_hashtags (pseudo_id, hashtag) VALUES (?, ?)";
    
        foreach ($hashtags as $hashtag) {
            try {
                $params = [
                    $this->pseudoId->getId(),
                    (string) $hashtag->getHashtag()
                ];

                $prepared = new Custom();
                $prepared->query($cql, $params);

                $this->db->request($prepared, true);
            } catch (\Exception $e) {
                error_log(static::class . '::add() CQL Exception ' . $e->getMessage());
                return false;
            }
        }

        return true;
    }

    /**
     * @param HashtagEntity[] $hashtags
     * @return bool
     * @throws \Exception
     */
    public function addTags(array $hashtags): bool
    {
        return $this->syncTags($hashtags);
    }

    /**
     * @param HashtagEntity[] $hashtags
     * @return bool
     * @throws \Exception
     */
    public function removeTags(array $hashtags): bool
    {
        $cql = "DELETE FROM pseduo_user_hashtags WHERE pseudo_id = ? AND hashtag = ?";
    
        foreach ($hashtags as $hashtag) {
            try {
                $params = [
                    $this->pseudoId->getId(),
                    (string) $hashtag->getHashtag()
{'fraction_non_alphanumeric': 0.12886937431394072, 'fraction_numerical': 0.0, 'mean_word_length': 2.0353097934710194, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 31, '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': '958186', 'n_tokens_mistral': 1436, 'n_tokens_neox': 1369, 'n_words': 307}