masukomi / masukomi/backup_brain
[feature] store a bookmark's favicon in MongoDB
Nobody has claimed this yet.
- Dominant language
- Ruby
- Stars
- 12
- Forks
- 2
- PR merge metrics
- No merged PRs in 30d
Description
Use cases:
- As a user I'd like to be able to see my bookmark's favicons even when not online.
- As a user I'd like to minimize the traffic sent to google because bandwidth is expensive in many parts of the world, and cell connections are slow in other parts of the world.
- As a user I'd like the app to be as fast as possible with no unnecessary network calls slowing things down.
MongoDB 's mongoid ruby driver supports a BSON::Binary data type (elsewhere referred to as BinData). Which is good for files of less than 16Mb.
My thinking is:
- when a bookmark is added 2 background jobs are spawned.
- one to archive it
- one to retrieve the favicon from google, using the current method, but in the background
- the binary data is ingested from google, and stored in the db in a new
Domainobject. - the Bookmark model
has_one: :domain(belongs_to???) and the domain has afield :favicon, type: BSON::Binary - when a bookmark is loaded on the web page, the view queries the domain to see if it has a favicon in the db and uses it if it does.
Things I'm unsure about:
- What's the incantation to ingest binary data into a db field?
Serving
(example from here
class PhotosController < ApplicationController
def serve
@photo = Photo.find(params[:id])
send_data(
@photo.data, # a binary column / field in your db. in our case BSON::Binary
:type => @photo.mime_type,
:filename => "#{@photo.name}.png", # but with dynamic suffix based on mime type
:disposition => "inline"
)
end
end
Storing
We probably need an Image model because we'd need to store mime type too (favicons can come in multiple types) and it wouldn't make any sense to store that on a Domain model.
Routing
# rails3
resources :photos do
get "serve", :on => :member
end
View
<%= image_tag serve_photo_path(@photo) %>
(serve_photo_path is because of the route defined above)
How to Download
- read this
- install the down gem
- download to temp file
- then...
"then the step after downloading the file to a Tempfile would be to set the field value to the value of the tempfile's content.
So if it's a variable named
foothen you'd want to do something like:record.image_field = foo.rewind.read
via Kevin Lawler on mastodon post
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the existing favicon retrieval method and bookmark view, then examine how Bookmark, Domain, and the proposed Image model could relate. Check Mongoid's BSON::Binary handling and the serving, storing, routing, and download examples in the issue. Done means favicon data and its MIME type are persisted and served from MongoDB so bookmarks can display them without repeated network calls.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- mongodb, rails, ruby
- Domain
- backend, database
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100