Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ GEM
mime-types
mimemagic (~> 0.3.0)
terrapin (~> 0.6.0)
rack (2.0.6)
rack (2.0.8)
rack-test (1.1.0)
rack (>= 1.0, < 3)
rails (5.2.2)
Expand Down
31 changes: 30 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,33 @@ This won't do you much good if you don't have the data, but this is my attempt t

It took too long, but it works.

I'll be putting the sql export up at some point so you can play with this yourself, and maybe make it prettier, more responsive, etc.
## Local Setup

### Requirements

* Ruby 2.6.3
* MySQL or MariaDB
* The default database.yml is localhost, and root w/out a password.
* The database name is `ficly_export`

### Getting the Data

The sql file to import is in db/export.sql.gz. It's a little over 600mb uncompressed. So, you'll need to do something like:

```cd db
gunzip export.sql.gz
mysql < export.sql
```

### Setting up Rails

* You'll need to install Ruby 2.6.3 however you want to make that happen.
* Install the bundler gem: `gem install bundler`
* `bundle`

And there you go!

## TODO

* Could be better looking, especially on mobile. You're welcome to help with that and submit a pull request!
* Speed up the export process. You're also welcome to help with that. To look at the monster as it is, check out lib/tasks/export.rake.
8 changes: 4 additions & 4 deletions app/controllers/tags_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@ class TagsController < ApplicationController
def index
@page = params[:page].to_i
@page = 1 if @page < 1
@tags = Tag.where.not(cleaned_tag: [nil, "", '-']).order('stories_count desc, cleaned_tag asc').paginate(page: @page, per_page: 250)
@tags = Tag.where.not(cleaned_tag: [nil, "", '-']).where("stories_count > 0").order('stories_count desc, cleaned_tag asc').paginate(page: @page, per_page: 250)
end

def show
@tag = Tag.find_by(cleaned_tag: params[:id])
story_ids = @tag.taggings.where(taggable_type: "Story").pluck(:taggable_id)
@stories = Story.published.where(id: story_ids).order("published_at asc").paginate(page: 1, per_page: 50)
challenge_ids = @tag.taggings.where(taggable_type: "Challenge").pluck(:taggable_id)
@challenges = Challenge.where(id: challenge_ids).order("id asc").paginate(page: 1, per_page: 50)
# challenge_ids = @tag.taggings.where(taggable_type: "Challenge").pluck(:taggable_id)
# @challenges = Challenge.where(id: challenge_ids).order("id asc").paginate(page: 1, per_page: 50)
end

def stories
@tag = Tag.find_by(cleaned_tag: params[:id])
@page = params[:page].to_i
@page = 1 if @page < 1
story_ids = @tag.taggings.where(taggable_type: "Story").pluck(:taggable_id)
@stories = Story.published.where(id: story_ids).order("published_at asc").paginate(page: @page, per_page: 50)
@stories = Story.published.where(id: story_ids).includes(:user).order("published_at asc").paginate(page: @page, per_page: 50)
end
#
# def challenges
Expand Down
6 changes: 3 additions & 3 deletions app/models/tag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ def self.calculate_counts
end

def calculate_counts
story_ids = self.taggings.where(taggable_type: "Story").pluck(:taggable_id)
story_ids = self.taggings.where(taggable_type: "Story").distinct.pluck(:taggable_id)
self.stories_count = Story.published.where(id: story_ids).count
challenge_ids = self.taggings.where(taggable_type: "Challenge").pluck(:taggable_id)
challenge_ids = self.taggings.where(taggable_type: "Challenge").distinct.pluck(:taggable_id)
self.challenges_count = challenge_ids.length
self.update_columns(stories_count: stories_count, challenges_count: challenges_count)
self.update_columns(stories_count: stories_count, challenges_count: challenges_count) if self.changed?
end

def stories
Expand Down
8 changes: 8 additions & 0 deletions bin/deploy
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/sh
USER=ficly_archive
HOST=export.ficly.com
DIR=export.ficly.com/ # might sometimes be empty!

rsync -avz --delete tmp/export/ ${USER}@${HOST}:~/${DIR}

exit 0
Binary file added db/export.sql.gz
Binary file not shown.
20 changes: 13 additions & 7 deletions lib/tasks/export.rake
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ namespace :export do
task :tags => :environment do
api.get("/tags")

total_pages = Tag.where.not(cleaned_tag: [nil, "", '-']).paginate(page: @page, per_page: 250).total_pages
total_pages = Tag.where.not(cleaned_tag: [nil, "", '-']).where("stories_count > 0").paginate(page: @page, per_page: 250).total_pages

i = 1

Expand All @@ -91,12 +91,18 @@ namespace :export do
i += 1
end

Tag.where.not(cleaned_tag: [nil, "", '-']).find_each do |tag|
story_ids = tag.taggings.where(taggable_type: "Story").pluck(:taggable_id)
total_pages = Story.published.where(id: story_ids).order("published_at asc").paginate(page: 1, per_page: 50).total_pages
i = 0
while i <= total_pages
api.get("/tags/#{tag.cleaned_name}/stories/#{i}")
Tag.where.not(cleaned_tag: [nil, "", '-']).where("stories_count > 0").order("stories_count desc").find_each do |tag|
api.get("/tags/#{tag.cleaned_tag}/stories")

story_ids = tag.taggings.where(taggable_type: "Story").distinct.pluck(:taggable_id)
total_pages = Story.published.where(id: story_ids).paginate(page: 1, per_page: 50).total_pages
i = 1

if total_pages > 1
while i <= total_pages
api.get("/tags/#{tag.cleaned_tag}/stories/#{i}")
i += 1
end
end
end

Expand Down