Migration to nano

This commit is contained in:
Eduard Urbach 2017-11-01 09:45:14 +01:00
parent 32d7378e87
commit c60f53ed76
7 changed files with 228 additions and 212 deletions

View File

@ -13,6 +13,7 @@ var popularity = map[string]*arn.AnimePopularity{}
// made to it. // made to it.
func main() { func main() {
color.Yellow("Updating anime ratings") color.Yellow("Updating anime ratings")
defer arn.Node.Close()
allAnimeLists, err := arn.AllAnimeLists() allAnimeLists, err := arn.AllAnimeLists()
arn.PanicOnError(err) arn.PanicOnError(err)
@ -58,7 +59,7 @@ func main() {
anime, err := arn.GetAnime(animeID) anime, err := arn.GetAnime(animeID)
arn.PanicOnError(err) arn.PanicOnError(err)
anime.Rating = finalRating[animeID] anime.Rating = finalRating[animeID]
arn.PanicOnError(anime.Save()) anime.Save()
} }
// Save popularity // Save popularity
@ -66,7 +67,7 @@ func main() {
anime, err := arn.GetAnime(animeID) anime, err := arn.GetAnime(animeID)
arn.PanicOnError(err) arn.PanicOnError(err)
anime.Popularity = popularity[animeID] anime.Popularity = popularity[animeID]
arn.PanicOnError(anime.Save()) anime.Save()
} }
color.Green("Finished.") color.Green("Finished.")

View File

@ -21,6 +21,7 @@ var wg sync.WaitGroup
// Main // Main
func main() { func main() {
color.Yellow("Generating user avatars") color.Yellow("Generating user avatars")
defer arn.Node.Close()
// Switch to main directory // Switch to main directory
exe, err := os.Executable() exe, err := os.Executable()

View File

@ -23,9 +23,7 @@ var colorPool = []*color.Color{
} }
var jobs = map[string]time.Duration{ var jobs = map[string]time.Duration{
"forum-activity": 1 * time.Minute,
"anime-ratings": 10 * time.Minute, "anime-ratings": 10 * time.Minute,
"popular-anime": 20 * time.Minute,
"avatars": 1 * time.Hour, "avatars": 1 * time.Hour,
"test": 1 * time.Hour, "test": 1 * time.Hour,
"twist": 2 * time.Hour, "twist": 2 * time.Hour,

View File

@ -18,7 +18,7 @@ var packages = []string{
"github.com/animenotifier/shoboi", "github.com/animenotifier/shoboi",
"github.com/animenotifier/twist", "github.com/animenotifier/twist",
"github.com/animenotifier/avatar", "github.com/animenotifier/avatar",
"github.com/animenotifier/japanese", // "github.com/animenotifier/japanese",
// "github.com/animenotifier/osu", // "github.com/animenotifier/osu",
} }

View File

@ -13,15 +13,17 @@ import (
var rateLimiter = time.NewTicker(500 * time.Millisecond) var rateLimiter = time.NewTicker(500 * time.Millisecond)
func main() { func main() {
defer arn.Node.Close()
// Replace this with ID list from twist.moe later // Replace this with ID list from twist.moe later
twistAnime, err := twist.GetAnimeIndex() twistAnime, err := twist.GetAnimeIndex()
arn.PanicOnError(err) arn.PanicOnError(err)
idList := twistAnime.KitsuIDs() idList := twistAnime.KitsuIDs()
// Save index in cache // Save index in cache
arn.PanicOnError(arn.DB.Set("Cache", "animetwist index", &arn.ListOfIDs{ arn.DB.Set("Cache", "animetwist index", &arn.ListOfIDs{
IDList: idList, IDList: idList,
})) })
color.Yellow("Refreshing twist.moe links for %d anime", len(idList)) color.Yellow("Refreshing twist.moe links for %d anime", len(idList))

View File

@ -11,7 +11,7 @@ import (
"github.com/animenotifier/notify.moe/utils" "github.com/animenotifier/notify.moe/utils"
) )
const maxPosts = 5 const maxForumActivity = 5
const maxFollowing = 5 const maxFollowing = 5
const maxSoundTracks = 5 const maxSoundTracks = 5
const maxScheduleItems = 5 const maxScheduleItems = 5
@ -30,7 +30,21 @@ func Get(ctx *aero.Context) string {
} }
flow.Parallel(func() { flow.Parallel(func() {
forumActivity, _ = arn.GetForumActivityCached() posts := arn.AllPosts()
threads := arn.AllThreads()
arn.SortPostsLatestFirst(posts)
arn.SortThreadsLatestFirst(threads)
posts = arn.FilterPostsWithUniqueThreads(posts, maxForumActivity)
postPostables := arn.ToPostables(posts)
threadPostables := arn.ToPostables(threads)
allPostables := append(postPostables, threadPostables...)
arn.SortPostablesLatestFirst(allPostables)
forumActivity = arn.FilterPostablesWithUniqueThreads(allPostables, maxForumActivity)
}, func() { }, func() {
animeList, err := arn.GetAnimeList(user.ID) animeList, err := arn.GetAnimeList(user.ID)

View File

@ -1,273 +1,273 @@
package main // package main
import ( // import (
"time" // "time"
"github.com/aerogo/database" // "github.com/aerogo/nano"
"github.com/animenotifier/arn" // "github.com/animenotifier/arn"
"github.com/fatih/color" // "github.com/fatih/color"
) // )
func main() { // func main() {
arn.DB.SetScanPriority("high") // arn.DB.SetScanPriority("high")
aeroDB := database.New("arn", arn.DBTypes) // aeroDB := nano.New(5000).Namespace("arn", arn.DBTypes...)
defer aeroDB.Close() // defer aeroDB.Close()
for typeName := range arn.DB.Types() { // for typeName := range arn.DB.Types() {
count := 0 // count := 0
switch typeName { // switch typeName {
case "Anime": // case "Anime":
channel, _ := arn.DB.All(typeName) // channel, _ := arn.DB.All(typeName)
for obj := range channel.(chan *arn.Anime) { // for obj := range channel.(chan *arn.Anime) {
aeroDB.Set(typeName, obj.ID, obj) // aeroDB.Set(typeName, obj.ID, obj)
count++ // count++
} // }
case "AnimeEpisodes": // case "AnimeEpisodes":
channel, _ := arn.DB.All(typeName) // channel, _ := arn.DB.All(typeName)
for obj := range channel.(chan *arn.AnimeEpisodes) { // for obj := range channel.(chan *arn.AnimeEpisodes) {
aeroDB.Set(typeName, obj.AnimeID, obj) // aeroDB.Set(typeName, obj.AnimeID, obj)
count++ // count++
} // }
case "AnimeList": // case "AnimeList":
channel, _ := arn.DB.All(typeName) // channel, _ := arn.DB.All(typeName)
for obj := range channel.(chan *arn.AnimeList) { // for obj := range channel.(chan *arn.AnimeList) {
aeroDB.Set(typeName, obj.UserID, obj) // aeroDB.Set(typeName, obj.UserID, obj)
count++ // count++
} // }
case "AnimeCharacters": // case "AnimeCharacters":
channel, _ := arn.DB.All(typeName) // channel, _ := arn.DB.All(typeName)
for obj := range channel.(chan *arn.AnimeCharacters) { // for obj := range channel.(chan *arn.AnimeCharacters) {
aeroDB.Set(typeName, obj.AnimeID, obj) // aeroDB.Set(typeName, obj.AnimeID, obj)
count++ // count++
} // }
case "AnimeRelations": // case "AnimeRelations":
channel, _ := arn.DB.All(typeName) // channel, _ := arn.DB.All(typeName)
for obj := range channel.(chan *arn.AnimeRelations) { // for obj := range channel.(chan *arn.AnimeRelations) {
aeroDB.Set(typeName, obj.AnimeID, obj) // aeroDB.Set(typeName, obj.AnimeID, obj)
count++ // count++
} // }
case "Character": // case "Character":
channel, _ := arn.DB.All(typeName) // channel, _ := arn.DB.All(typeName)
for obj := range channel.(chan *arn.Character) { // for obj := range channel.(chan *arn.Character) {
aeroDB.Set(typeName, obj.ID, obj) // aeroDB.Set(typeName, obj.ID, obj)
count++ // count++
} // }
case "Purchase": // case "Purchase":
channel, _ := arn.DB.All(typeName) // channel, _ := arn.DB.All(typeName)
for obj := range channel.(chan *arn.Purchase) { // for obj := range channel.(chan *arn.Purchase) {
aeroDB.Set(typeName, obj.ID, obj) // aeroDB.Set(typeName, obj.ID, obj)
count++ // count++
} // }
case "PushSubscriptions": // case "PushSubscriptions":
channel, _ := arn.DB.All(typeName) // channel, _ := arn.DB.All(typeName)
for obj := range channel.(chan *arn.PushSubscriptions) { // for obj := range channel.(chan *arn.PushSubscriptions) {
aeroDB.Set(typeName, obj.UserID, obj) // aeroDB.Set(typeName, obj.UserID, obj)
count++ // count++
} // }
case "User": // case "User":
channel, _ := arn.DB.All(typeName) // channel, _ := arn.DB.All(typeName)
for obj := range channel.(chan *arn.User) { // for obj := range channel.(chan *arn.User) {
aeroDB.Set(typeName, obj.ID, obj) // aeroDB.Set(typeName, obj.ID, obj)
count++ // count++
} // }
case "Post": // case "Post":
channel, _ := arn.DB.All(typeName) // channel, _ := arn.DB.All(typeName)
for obj := range channel.(chan *arn.Post) { // for obj := range channel.(chan *arn.Post) {
aeroDB.Set(typeName, obj.ID, obj) // aeroDB.Set(typeName, obj.ID, obj)
count++ // count++
} // }
case "Thread": // case "Thread":
channel, _ := arn.DB.All(typeName) // channel, _ := arn.DB.All(typeName)
for obj := range channel.(chan *arn.Thread) { // for obj := range channel.(chan *arn.Thread) {
aeroDB.Set(typeName, obj.ID, obj) // aeroDB.Set(typeName, obj.ID, obj)
count++ // count++
} // }
case "Analytics": // case "Analytics":
channel, _ := arn.DB.All(typeName) // channel, _ := arn.DB.All(typeName)
for obj := range channel.(chan *arn.Analytics) { // for obj := range channel.(chan *arn.Analytics) {
aeroDB.Set(typeName, obj.UserID, obj) // aeroDB.Set(typeName, obj.UserID, obj)
count++ // count++
} // }
case "SoundTrack": // case "SoundTrack":
channel, _ := arn.DB.All(typeName) // channel, _ := arn.DB.All(typeName)
for obj := range channel.(chan *arn.SoundTrack) { // for obj := range channel.(chan *arn.SoundTrack) {
aeroDB.Set(typeName, obj.ID, obj) // aeroDB.Set(typeName, obj.ID, obj)
count++ // count++
} // }
case "Item": // case "Item":
channel, _ := arn.DB.All(typeName) // channel, _ := arn.DB.All(typeName)
for obj := range channel.(chan *arn.Item) { // for obj := range channel.(chan *arn.Item) {
aeroDB.Set(typeName, obj.ID, obj) // aeroDB.Set(typeName, obj.ID, obj)
count++ // count++
} // }
case "Inventory": // case "Inventory":
channel, _ := arn.DB.All(typeName) // channel, _ := arn.DB.All(typeName)
for obj := range channel.(chan *arn.Inventory) { // for obj := range channel.(chan *arn.Inventory) {
aeroDB.Set(typeName, obj.UserID, obj) // aeroDB.Set(typeName, obj.UserID, obj)
count++ // count++
} // }
case "Settings": // case "Settings":
channel, _ := arn.DB.All(typeName) // channel, _ := arn.DB.All(typeName)
for obj := range channel.(chan *arn.Settings) { // for obj := range channel.(chan *arn.Settings) {
aeroDB.Set(typeName, obj.UserID, obj) // aeroDB.Set(typeName, obj.UserID, obj)
count++ // count++
} // }
case "UserFollows": // case "UserFollows":
channel, _ := arn.DB.All(typeName) // channel, _ := arn.DB.All(typeName)
for obj := range channel.(chan *arn.UserFollows) { // for obj := range channel.(chan *arn.UserFollows) {
aeroDB.Set(typeName, obj.UserID, obj) // aeroDB.Set(typeName, obj.UserID, obj)
count++ // count++
} // }
case "PayPalPayment": // case "PayPalPayment":
channel, _ := arn.DB.All(typeName) // channel, _ := arn.DB.All(typeName)
for obj := range channel.(chan *arn.PayPalPayment) { // for obj := range channel.(chan *arn.PayPalPayment) {
aeroDB.Set(typeName, obj.ID, obj) // aeroDB.Set(typeName, obj.ID, obj)
count++ // count++
} // }
case "AniListToAnime": // case "AniListToAnime":
channel, _ := arn.DB.All(typeName) // channel, _ := arn.DB.All(typeName)
for obj := range channel.(chan *arn.AniListToAnime) { // for obj := range channel.(chan *arn.AniListToAnime) {
aeroDB.Set(typeName, obj.ServiceID, obj) // aeroDB.Set(typeName, obj.ServiceID, obj)
count++ // count++
} // }
case "MyAnimeListToAnime": // case "MyAnimeListToAnime":
channel, _ := arn.DB.All(typeName) // channel, _ := arn.DB.All(typeName)
for obj := range channel.(chan *arn.MyAnimeListToAnime) { // for obj := range channel.(chan *arn.MyAnimeListToAnime) {
aeroDB.Set(typeName, obj.ServiceID, obj) // aeroDB.Set(typeName, obj.ServiceID, obj)
count++ // count++
} // }
case "SearchIndex": // case "SearchIndex":
anime, _ := arn.DB.Get(typeName, "Anime") // anime, _ := arn.DB.Get(typeName, "Anime")
aeroDB.Set(typeName, "Anime", anime) // aeroDB.Set(typeName, "Anime", anime)
users, _ := arn.DB.Get(typeName, "User") // users, _ := arn.DB.Get(typeName, "User")
aeroDB.Set(typeName, "User", users) // aeroDB.Set(typeName, "User", users)
posts, _ := arn.DB.Get(typeName, "Post") // posts, _ := arn.DB.Get(typeName, "Post")
aeroDB.Set(typeName, "Post", posts) // aeroDB.Set(typeName, "Post", posts)
threads, _ := arn.DB.Get(typeName, "Thread") // threads, _ := arn.DB.Get(typeName, "Thread")
aeroDB.Set(typeName, "Thread", threads) // aeroDB.Set(typeName, "Thread", threads)
count += 4 // count += 4
case "DraftIndex": // case "DraftIndex":
channel, _ := arn.DB.All(typeName) // channel, _ := arn.DB.All(typeName)
for obj := range channel.(chan *arn.DraftIndex) { // for obj := range channel.(chan *arn.DraftIndex) {
aeroDB.Set(typeName, obj.UserID, obj) // aeroDB.Set(typeName, obj.UserID, obj)
count++ // count++
} // }
case "EmailToUser": // case "EmailToUser":
channel, _ := arn.DB.All(typeName) // channel, _ := arn.DB.All(typeName)
for obj := range channel.(chan *arn.EmailToUser) { // for obj := range channel.(chan *arn.EmailToUser) {
if obj.Email == "" { // if obj.Email == "" {
continue // continue
} // }
aeroDB.Set(typeName, obj.Email, obj) // aeroDB.Set(typeName, obj.Email, obj)
count++ // count++
} // }
case "FacebookToUser": // case "FacebookToUser":
channel, _ := arn.DB.All(typeName) // channel, _ := arn.DB.All(typeName)
for obj := range channel.(chan *arn.FacebookToUser) { // for obj := range channel.(chan *arn.FacebookToUser) {
if obj.ID == "" { // if obj.ID == "" {
continue // continue
} // }
aeroDB.Set(typeName, obj.ID, obj) // aeroDB.Set(typeName, obj.ID, obj)
count++ // count++
} // }
case "GoogleToUser": // case "GoogleToUser":
channel, _ := arn.DB.All(typeName) // channel, _ := arn.DB.All(typeName)
for obj := range channel.(chan *arn.GoogleToUser) { // for obj := range channel.(chan *arn.GoogleToUser) {
if obj.ID == "" { // if obj.ID == "" {
continue // continue
} // }
aeroDB.Set(typeName, obj.ID, obj) // aeroDB.Set(typeName, obj.ID, obj)
count++ // count++
} // }
case "TwitterToUser": // case "TwitterToUser":
channel, _ := arn.DB.All(typeName) // channel, _ := arn.DB.All(typeName)
for obj := range channel.(chan *arn.TwitterToUser) { // for obj := range channel.(chan *arn.TwitterToUser) {
if obj.ID == "" { // if obj.ID == "" {
continue // continue
} // }
aeroDB.Set(typeName, obj.ID, obj) // aeroDB.Set(typeName, obj.ID, obj)
count++ // count++
} // }
case "NickToUser": // case "NickToUser":
channel, _ := arn.DB.All(typeName) // channel, _ := arn.DB.All(typeName)
for obj := range channel.(chan *arn.NickToUser) { // for obj := range channel.(chan *arn.NickToUser) {
if obj.Nick == "" { // if obj.Nick == "" {
continue // continue
} // }
aeroDB.Set(typeName, obj.Nick, obj) // aeroDB.Set(typeName, obj.Nick, obj)
count++ // count++
} // }
default: // default:
color.Yellow("Skipping %s", typeName) // color.Yellow("Skipping %s", typeName)
continue // continue
} // }
color.Green("Export %d %s", count, typeName) // color.Green("Export %d %s", count, typeName)
} // }
time.Sleep(1 * time.Second) // time.Sleep(1 * time.Second)
} // }