There’s a problem with nested query I previously mentioned: query time is unstable. The worst case is at least as slow as multiple self-join method – when the first few search key result is too big.
Optimize all the queries!
While digging more into the code called “Moebooru” which was forked from “Danbooru”, I noticed this:
def self.included(m)
m.extend(ClassMethods)
m.after_create :increment_count
m.after_destroy :decrement_count
end
def increment_count
connection.execute("update table_data set row_count = row_count + 1 where name = 'users'")
end
def decrement_count
connection.execute("update table_data set row_count = row_count - 1 where name = 'users'")
end
Counting takes ages, right. Except it is not. I’ve done this, yes, but on a table with 10+ millions of data (this one has ~400k in mainline danbooru), with multiple data inserted (this one got, uh, one every other week?) and queried every second (see below), and with the required count method not a simple select count(1) on some_table (which is what the example above used for).
The best part? It’s only used once, when user registers:
def set_role
if User.fast_count == 0
self.level = CONFIG["user_levels"]["Admin"]
elsif CONFIG["enable_account_email_activation"]
self.level = CONFIG["user_levels"]["Unactivated"]
else
self.level = CONFIG["starting_level"]
end
self.last_logged_in_at = Time.now
end
Moebooru Update
I haven’t been able to work on Moebooru for most of this month but I got to work on it this weekend. At ~30 changes, it went from -alpha to -beta.2 after receiving good amount of tests.
Summary of changes (more or less):
- Most instances of RAILS_ENV and RAILS_ROOT have been replaced with newer Rails.env/Rails.root
- Better Javascript handling in Development mode by moving cached Javascript from application.js to cached/all.js
- Removed AssetCache modification library
- Replaced HTML5Sanitizer’s html5sanitize with Rails’ built-in sanitize (because the former doesn’t work in 1.9)
- Fixed Note Editor’s “History” button
- Fixed Comment page’s pagination
- Fixed Tag Relation search function
- Updated “hack” for UTF-8 handling in Rails 2.3 with Ruby 1.9
- Merged updates from moe branch (the one currently used in yande.re)
- Reverted change which put class definition in <html> tag as it currently required by Javascript
Searching Tags in (3NF) Database
This afternoon I experimented with tag searching in yande.re database. Current implementation doesn’t scale beyond 6 tags due to parsing requirement. You can argue about binding variable all day but in the end it can be abused easily if the limit is lifted.
zpool hourly status check
I’m setting up cron job for a storage server using ZFS. There’s zpool status -x but it returns “all pools are healthy” (or “no pools available”) on no error and prints errors to stdout (instead of stderr), rendering it annoying for cron job.
#!/bin/sh
set -e
set -u
zstatus="`zpool status -x 2>&1`"
case "${zstatus}" in
"all pools are healthy"|"no pools available")
return 0
;;
*)
printf "%s\n" "${zstatus}" >&2
return 1
;;
esac
Put it in a file (e.g. /root/bin/zpool-status-cron), make it executable, and add it to crontab.
Unofficial Sentai Akibaranger
A metaseries on Super Sentai. In short, they opened tvtropes and jammed as many tropes as they can into the series.
Head over to Over-Time to grab the releases (currently 2 episodes). Don’t forget to read the notes, too! I wish more fansubbers do this for reference-heavy series.
I’m pretty sure “Nijiyome” there is abbreviation of “nijigen yome” (2D waifu).
Haiyore! Nyarlko episode 1
Supipara demo movie
Demo movie for Supipara – minori’s latest game/series is out. No high quality video in sight though. And the animation isn’t by Shinkai – just like eden (and I suspect we’ll get no more minori/Shinkai combo) but still pretty enough so it’s okay.
As expected, there’s no male in sight. The game is all-ages though so we won’t get some actual yuri action either
[ Link to video ]
Accel World
One of the hyped series for this season, spring 2012. Looks quite good. With Sunrise as production studio, I can safely expect stable animation over the series. No clear indication on how long this will be though considering the amount of its LN, I guess half-assed ending should be expected.
And yes, Black Snow Princess (aka Kuroyukihime) makes up 90+% of reason I’m watching this as of currently :>
![[Over-Time] Unofficial Sentai Akibaranger - 02 [4B0EC4A2].mkv_snapshot_16.04_[2012.04.18_18.54.39]](http://animebsd.net/wp-content/uploads/2012/04/Over-Time-Unofficial-Sentai-Akibaranger-02-4B0EC4A2.mkv_snapshot_16.04_2012.04.18_18.54.39-1024x576.jpg)
![[Commie] Haiyore! Nyarlko - 01 [9BCF9CCC].mkv_snapshot_20.45_[2012.04.10_20.19.26]](http://animebsd.net/wp-content/uploads/2012/04/Commie-Haiyore-Nyarlko-01-9BCF9CCC.mkv_snapshot_20.45_2012.04.10_20.19.26-1024x576.jpg)
![すぴぱら_Alice_the_magical_conductor_STORY_01_Spring_Has_Come_demo_movie.flv_snapshot_01.19_[2012.04.09_08.08.43]](http://animebsd.net/wp-content/uploads/2012/04/すぴぱら_Alice_the_magical_conductor_STORY_01_Spring_Has_Come_demo_movie.flv_snapshot_01.19_2012.04.09_08.08.43.jpg)

![[gg] Aquarion EVOL - 03 [8F68A324].mkv_snapshot_20.51_[2012.04.06_20.17.32]](http://animebsd.net/wp-content/uploads/2012/04/gg-Aquarion-EVOL-03-8F68A324.mkv_snapshot_20.51_2012.04.06_20.17.32-1024x576.jpg)