Improved forum database

This commit is contained in:
Eduard Urbach 2017-06-26 23:41:16 +02:00
parent db28721126
commit e7d914f223
7 changed files with 84 additions and 21 deletions

View File

@ -12,7 +12,6 @@ component Layout(app *aero.Application, ctx *aero.Context, user *arn.User, conte
Navigation(user) Navigation(user)
#content-container #content-container
main#content.fade!= content main#content.fade!= content
LoadingAnimation LoadingAnimation
script(src="/scripts") script(src="/scripts")

View File

@ -8,6 +8,6 @@ component ThreadLink(thread *arn.Thread)
Icon("thumb-tack") Icon("thumb-tack")
a.thread-link-title.ajax(href="/threads/" + thread.ID)= thread.Title a.thread-link-title.ajax(href="/threads/" + thread.ID)= thread.Title
.spacer .spacer
.thread-reply-count= thread.Replies .thread-reply-count= len(thread.Posts)
.thread-icons .thread-icons
Icon(arn.GetForumIcon(thread.Tags[0])) Icon(arn.GetForumIcon(thread.Tags[0]))

View File

@ -1,7 +1,7 @@
package threads package threads
import ( import (
"strings" "net/http"
"github.com/aerogo/aero" "github.com/aerogo/aero"
"github.com/animenotifier/arn" "github.com/animenotifier/arn"
@ -12,28 +12,26 @@ import (
// Get thread. // Get thread.
func Get(ctx *aero.Context) string { func Get(ctx *aero.Context) string {
id := ctx.Get("id") id := ctx.Get("id")
thread, err := arn.GetThread(id)
user := utils.GetUser(ctx) user := utils.GetUser(ctx)
// Fetch thread
thread, err := arn.GetThread(id)
if err != nil { if err != nil {
return ctx.Error(404, "Thread not found", err) return ctx.Error(http.StatusNotFound, "Thread not found", err)
} }
replies, filterErr := arn.FilterPosts(func(post *arn.Post) bool { // Fetch posts
post.Text = strings.Replace(post.Text, "http://", "https://", -1) postObjects, getErr := arn.DB.GetMany("Post", thread.Posts)
return post.ThreadID == thread.ID
})
arn.SortPostsLatestLast(replies) if getErr != nil {
return ctx.Error(http.StatusInternalServerError, "Could not retrieve posts", getErr)
// Benchmark
// for i := 0; i < 7; i++ {
// replies = append(replies, replies...)
// }
if filterErr != nil {
return ctx.Error(500, "Error fetching thread replies", err)
} }
return ctx.HTML(components.Thread(thread, replies, user)) posts := postObjects.([]*arn.Post)
// Sort posts
arn.SortPostsLatestLast(posts)
return ctx.HTML(components.Thread(thread, posts, user))
} }

View File

@ -0,0 +1,29 @@
package main
import (
"github.com/animenotifier/arn"
"github.com/fatih/color"
)
func main() {
// Get a stream of all posts
allPosts, err := arn.AllPosts()
arn.PanicOnError(err)
// Iterate over the stream
for post := range allPosts {
// Fix text
color.Yellow(post.Text)
post.Text = arn.FixPostText(post.Text)
color.Green(post.Text)
// Tags
if post.Tags == nil {
post.Tags = []string{}
}
// Save
err = post.Save()
arn.PanicOnError(err)
}
}

View File

@ -0,0 +1,34 @@
package main
import (
"github.com/animenotifier/arn"
)
func main() {
// Get a stream of all posts
allPosts, err := arn.AllPosts()
arn.PanicOnError(err)
threadToPosts := make(map[string][]string)
// Iterate over the stream
for post := range allPosts {
_, found := threadToPosts[post.ThreadID]
if !found {
threadToPosts[post.ThreadID] = []string{post.ID}
} else {
threadToPosts[post.ThreadID] = append(threadToPosts[post.ThreadID], post.ID)
}
}
// Save new post ID lists
for threadID, posts := range threadToPosts {
thread, err := arn.GetThread(threadID)
arn.PanicOnError(err)
thread.Posts = posts
err = thread.Save()
arn.PanicOnError(err)
}
}

View File

@ -40,6 +40,9 @@ nav-link-hover-slide-color = rgb(248, 165, 130)
// nav-link-color = rgb(160, 160, 160) // nav-link-color = rgb(160, 160, 160)
// nav-link-hover-color = rgb(80, 80, 80) // nav-link-hover-color = rgb(80, 80, 80)
// Loading animation
loading-anim-color = nav-link-hover-slide-color
// Shadow // Shadow
shadow-light = 4px 4px 8px rgba(0, 0, 0, 0.05) shadow-light = 4px 4px 8px rgba(0, 0, 0, 0.05)
shadow-medium = 6px 6px 12px rgba(0, 0, 0, 0.13) shadow-medium = 6px 6px 12px rgba(0, 0, 0, 0.13)

View File

@ -17,7 +17,7 @@ loading-anim-size = 24px
.sk-cube .sk-cube
width 33.3% width 33.3%
height 33.3% height 33.3%
background-color main-color background-color loading-anim-color
opacity 0.7 opacity 0.7
border-radius 100% border-radius 100%
animation sk-pulse loading-anim-duration infinite linear animation sk-pulse loading-anim-duration infinite linear