<commit_before>require 'rollbar'
require_relative '../../models/visualization/member'
require_relative '../../models/visualization/collection'
require_relative '../../models/visualization/external_source'
require_relative '../../models/common_data/singleton'

module CartoDB

  module Visualization

    class CommonDataService

      def initialize(datasets = nil)
        @datasets = datasets
      end

      def self.load_common_data(user, controller)
        if configured?
          common_data_url = CartoDB::Visualization::CommonDataService.build_url(controller)
          @user.load_common_data(common_data_url)
        end
      end

      def self.configured?
        !Cartodb.config[:common_data].nil?
      end

      def self.build_url(controller)
        common_data_base_url = Cartodb.config[:common_data]['base_url']
        common_data_username = Cartodb.config[:common_data]['username']
        common_data_user = Carto::User.where(username: common_data_username).first
        if !common_data_base_url.nil?
          # We set user_domain to nil to avoid duplication in the url for subdomainfull urls. Ie. user.cartodb.com/u/cartodb/...
          common_data_base_url + CartoDB.path(controller, 'api_v1_visualizations_index', {type: 'table', privacy: 'public', user_domain: nil})
        elsif !common_data_user.nil?
          CartoDB.url(controller, 'api_v1_visualizations_index', {type: 'table', privacy: 'public'}, common_data_user)
        else
          CartoDB.notify_error(
            'cant create common-data url. User doesn\'t exist and base_url is nil',
            user: common_data_username
          )
        end
      end

      def load_common_data_for_user(user, visualizations_api_url)
        update_user_date_flag(user)

        added = 0
        updated = 0
        not_modified = 0
        deleted = 0<commit_msg>@user fix<commit_after>require 'rollbar'
require_relative '../../models/visualization/member'
require_relative '../../models/visualization/collection'
require_relative '../../models/visualization/external_source'
require_relative '../../models/common_data/singleton'

module CartoDB

  module Visualization

    class CommonDataService

      def initialize(datasets = nil)
        @datasets = datasets
      end

      def self.load_common_data(user, controller)
        if configured?
          common_data_url = CartoDB::Visualization::CommonDataService.build_url(controller)
          user.load_common_data(common_data_url)
        end
      end

      def self.configured?
        !Cartodb.config[:common_data].nil?
      end

      def self.build_url(controller)
        common_data_base_url = Cartodb.config[:common_data]['base_url']
        common_data_username = Cartodb.config[:common_data]['username']
        common_data_user = Carto::User.where(username: common_data_username).first
        if !common_data_base_url.nil?
          # We set user_domain to nil to avoid duplication in the url for subdomainfull urls. Ie. user.cartodb.com/u/cartodb/...
          common_data_base_url + CartoDB.path(controller, 'api_v1_visualizations_index', {type: 'table', privacy: 'public', user_domain: nil})
        elsif !common_data_user.nil?
          CartoDB.url(controller, 'api_v1_visualizations_index', {type: 'table', privacy: 'public'}, common_data_user)
        else
          CartoDB.notify_error(
            'cant create common-data url. User doesn\'t exist and base_url is nil',
            user: common_data_username
          )
        end
      end

      def load_common_data_for_user(user, visualizations_api_url)
        update_user_date_flag(user)

        added = 0
        updated = 0
        not_modified = 0
        deleted = 0
{'fraction_non_alphanumeric': 0.0960863697705803, 'fraction_numerical': 0.0032388663967611335, 'mean_word_length': 2.9010526315789473, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '3514427', 'n_tokens_mistral': 1111, 'n_tokens_neox': 1075, 'n_words': 220}