<commit_before>require "../resources/db/package"
require "../resources/db/package_deps"

include Sharock::Resources

module Sharock::Services
  class PackageService
    def initialize(@pool)
    end

    def find_one(host, owner, repo)
      @pool.connect do |conn|
        package = PackageResource.new(conn).find_one(host, owner, repo)
        package.try do |package|
          package_deps = PackageDepsResource.new(conn).find_one_latest_version(package.id)
          package_deps.try do |package_deps|
            return Entities::Results::Package.new(package, package_deps)
          end
        end
      end
    end

    def update_deps(id, deps)
      p id
      p deps
    end

    def needs_syncing(package : Entities::Results::Package?)
      package.try do |package|
        package.package.sync_started_at.try do |sync_started_at|
          span = Time.now - sync_started_at
          return span.seconds > Config::CACHE_TIME_SEC
        end

        return true
      end<commit_msg>feat(services/package): implement `update_deps` method<commit_after>require "../resources/db/package"
require "../resources/db/package_deps"

include Sharock::Resources

module Sharock::Services
  class PackageService
    def initialize(@pool)
    end

    def find_one(host, owner, repo)
      @pool.connect do |conn|
        package = PackageResource.new(conn).find_one(host, owner, repo)
        package.try do |package|
          package_deps = PackageDepsResource.new(conn).find_one_latest_version(package.id)
          package_deps.try do |package_deps|
            return Entities::Results::Package.new(package, package_deps)
          end
        end
      end
    end

    def update_deps(package_id, deps)
      @pool.connect do |conn|
        package_resource = PackageResource.new(conn)
        package_resource.update_deps(
          package_id,
          "unknown",
          "unknown",
          deps.to_json
        )
      end
    end

    def needs_syncing(package : Entities::Results::Package?)
      package.try do |package|
        package.package.sync_started_at.try do |sync_started_at|
          span = Time.now - sync_started_at
          return span.seconds > Config::CACHE_TIME_SEC
        end

        return true
      end
{'fraction_non_alphanumeric': 0.09026233881725211, 'fraction_numerical': 0.0, 'mean_word_length': 2.515625, 'pattern_counts': {'":': 0, '<': 3, '<?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': '2815116', 'n_tokens_mistral': 671, 'n_tokens_neox': 656, 'n_words': 141}