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.
func main() {
color.Yellow("Updating anime ratings")
defer arn.Node.Close()
allAnimeLists, err := arn.AllAnimeLists()
arn.PanicOnError(err)
@ -58,7 +59,7 @@ func main() {
anime, err := arn.GetAnime(animeID)
arn.PanicOnError(err)
anime.Rating = finalRating[animeID]
arn.PanicOnError(anime.Save())
anime.Save()
}
// Save popularity
@ -66,7 +67,7 @@ func main() {
anime, err := arn.GetAnime(animeID)
arn.PanicOnError(err)
anime.Popularity = popularity[animeID]
arn.PanicOnError(anime.Save())
anime.Save()
}
color.Green("Finished.")

View File

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

View File

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

View File

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

View File

@ -13,15 +13,17 @@ import (
var rateLimiter = time.NewTicker(500 * time.Millisecond)
func main() {
defer arn.Node.Close()
// Replace this with ID list from twist.moe later
twistAnime, err := twist.GetAnimeIndex()
arn.PanicOnError(err)
idList := twistAnime.KitsuIDs()
// Save index in cache
arn.PanicOnError(arn.DB.Set("Cache", "animetwist index", &arn.ListOfIDs{
arn.DB.Set("Cache", "animetwist index", &arn.ListOfIDs{
IDList: 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"
)
const maxPosts = 5
const maxForumActivity = 5
const maxFollowing = 5
const maxSoundTracks = 5
const maxScheduleItems = 5
@ -30,7 +30,21 @@ func Get(ctx *aero.Context) string {
}
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() {
animeList, err := arn.GetAnimeList(user.ID)

View File

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