This file collects various notes about how certain aspects are implemented.

# Full text search

The pg_search Ruby gem is used for full-text searched in Rails.
See: https://github.com/Casecommons/pg_search

Reformatted SQL query for fulltext search:

SELECT COUNT(*) FROM "packages" WHERE (
  (
    (
      to_tsvector('simple', coalesce("packages"."name"::text, ''))
      ||
      to_tsvector('simple', coalesce("packages"."description"::text, ''))
      ||
      to_tsvector('simple', coalesce("packages"."long_description"::text, ''))
    )
    @@
    (
      to_tsquery('simple', '''' || 'browser' || ' ''')
    )
  )
)

## Create search index to speed up searches significantly

CREATE INDEX packages_gin ON packages USING GIN( (to_tsvector('simple',
coalesce("packages"."name"::text, '')) || to_tsvector('simple',
coalesce("packages"."description"::text, '')) || to_tsvector('simple',
coalesce("packages"."long_description"::text, ''))) );

---------

Used: https://github.com/semaperepelitsa/jquery.fileupload-rails
Which is a gem for: https://github.com/blueimp/jQuery-File-Upload

---

Paperclip for attachment/screenshot file handlind within ActiveRecord
https://github.com/thoughtbot/paperclip

Rails 5 is said to contain functionality like that already.
Might be worth migrating to that at some time.

---

Importer

How Debian repositories are organized: https://wiki.debian.org/RepositoryFormat

---

Logging from within the application into the database's "log" table:

auditlog "foo"
or with section (default='frontend'):
Log.log "foo", nil, nil, "importer"

---

To create admin users
---------------------

rails c
> User.new(email: 'email@christoph-haas.de', password: 'secret').save

---

Multiple distributions (e.g. Ubuntu, Debian)
- new table: distributions
  - id
  - name (e.g. "Debian")
  - description (e.g. "The Debian GNU/Linux distribution")
  - url (http://www.debian.org/)
  - type (apt, later: rpm)
  - logo

- screenshots: new field for source_id

Admin interface to manage sources

---

AppStream data
- screenshots: new field for type ('user-generated', 'upstream', 'logo')
  user-generated: uploaded by a random user
  upstream: official screenshot from the developer
  logo: not a screenshot - just a logo

---

debshots used to use the 'paperclip' gem for file handling of images.
Paperclip was deprecated so something new was needed. At the same time
Rails 6.0 was released and offered file handling using ActiveStorage.
However ActiveStorage was so seriously flawed and incomplete in 2020
that I decided to go for the 'shrine' gem.

There is a Rake task that converts Paperclip attachments to Shrine attachments.
This is a one-time conversion.

Images are saved in four ways:
- original image
- thumb image (to be used in packages.debian.org)
- large image (original image with watermark on the right edge)
- medium image (up to 800x600)
- small image (up to 320x240) for gallery/grid views
