• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pulibrary / orangelight / 62bad3f1-d46d-40af-822c-403d653da2a8

17 Jun 2025 05:30PM UTC coverage: 0.447% (-94.9%) from 95.337%
62bad3f1-d46d-40af-822c-403d653da2a8

push

circleci

maxkadel
Install chrome & chromedriver for smoke specs

43 of 9610 relevant lines covered (0.45%)

0.01 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/app/models/bookmark.rb
1
# frozen_string_literal: true
2

3
class Bookmark < ApplicationRecord
×
4
  belongs_to :user, polymorphic: true
×
5

6
  # TODO: remove the following scope, since as of
7
  # migration 20230419231330, the database layer
8
  # will not allow bookmarks without a valid user
9
  scope :without_valid_user, -> { where('user_id NOT IN (SELECT id FROM users)') }
×
10

11
  def document_type
×
12
    SolrDocument
×
13
  end
×
14

15
  def self.destroy_without_solr_documents
×
16
    batch_size = Orangelight.config["bookmarks"]["batch_size"]
×
17
    Bookmark.find_in_batches(batch_size:).with_index do |bookmarks, batch|
×
18
      Rails.logger.info { "Processing destroy_without_solr_documents group ##{batch}" }
×
19
      bookmark_doc_ids = bookmark_doc_ids(bookmarks)
×
20
      doc_ids_without_solr_doc = bookmark_doc_ids - doc_ids_in_solr(bookmark_doc_ids)
×
21

22
      if doc_ids_without_solr_doc.present?
×
23
        doc_ids_without_solr_doc.each do |doc_id|
×
24
          Bookmark.where(document_id: doc_id)&.destroy_all
×
25
        end
×
26
      end
×
27
    end
×
28
  end
×
29

30
  def self.update_to_alma_ids
×
31
    Bookmark.where("LENGTH(document_id) <= 7").find_in_batches.with_index do |bookmarks, batch|
×
32
      Rails.logger.info { "Processing update_to_alma_ids group ##{batch}" }
×
33
      bookmarks.each do |bookmark|
×
34
        bookmark.document_id = bookmark.voyager_to_alma_id
×
35
        bookmark.save if bookmark.changed?
×
36
      end
×
37
    end
×
38
  end
×
39

40
  def self.bookmark_doc_ids(bookmarks)
×
41
    bookmarks.map(&:document_id).to_set
×
42
  end
×
43

44
  def self.doc_ids_in_solr(bookmark_doc_ids)
×
45
    solr = Blacklight.default_index.connection
×
46
    rows = Orangelight.config["bookmarks"]["batch_size"]
×
47
    response = solr.get 'select', params: { fq: "{!terms f=id}#{bookmark_doc_ids.join(',')}", fl: 'id', rows: }
×
48
    response["response"]["docs"].map { |doc| doc["id"] }
×
49
  end
×
50

51
  def voyager_to_alma_id
×
52
    return document_id if alma_id?(document_id) || special_system_id?(document_id)
×
53

54
    "99#{document_id}3506421"
×
55
  end
×
56

57
  private
×
58

59
    def alma_id?(document_id)
×
60
      document_id.length > 7 && document_id.start_with?("99")
×
61
    end
×
62

63
    # If the document_id includes letters, it is not a Voyager or Alma ID
64
    # It may be a coin, SCSB, or DSpace ID
65
    def special_system_id?(document_id)
×
66
      document_id.match?(/[a-zA-Z]/)
×
67
    end
×
68
end
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc