Improved forum database
This commit is contained in:
parent
db28721126
commit
e7d914f223
@ -12,8 +12,7 @@ component Layout(app *aero.Application, ctx *aero.Context, user *arn.User, conte
|
||||
Navigation(user)
|
||||
#content-container
|
||||
main#content.fade!= content
|
||||
|
||||
LoadingAnimation
|
||||
LoadingAnimation
|
||||
script(src="/scripts")
|
||||
|
||||
component LoadingAnimation
|
||||
|
@ -8,6 +8,6 @@ component ThreadLink(thread *arn.Thread)
|
||||
Icon("thumb-tack")
|
||||
a.thread-link-title.ajax(href="/threads/" + thread.ID)= thread.Title
|
||||
.spacer
|
||||
.thread-reply-count= thread.Replies
|
||||
.thread-reply-count= len(thread.Posts)
|
||||
.thread-icons
|
||||
Icon(arn.GetForumIcon(thread.Tags[0]))
|
@ -1,7 +1,7 @@
|
||||
package threads
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"net/http"
|
||||
|
||||
"github.com/aerogo/aero"
|
||||
"github.com/animenotifier/arn"
|
||||
@ -12,28 +12,26 @@ import (
|
||||
// Get thread.
|
||||
func Get(ctx *aero.Context) string {
|
||||
id := ctx.Get("id")
|
||||
thread, err := arn.GetThread(id)
|
||||
user := utils.GetUser(ctx)
|
||||
|
||||
// Fetch thread
|
||||
thread, err := arn.GetThread(id)
|
||||
|
||||
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 {
|
||||
post.Text = strings.Replace(post.Text, "http://", "https://", -1)
|
||||
return post.ThreadID == thread.ID
|
||||
})
|
||||
// Fetch posts
|
||||
postObjects, getErr := arn.DB.GetMany("Post", thread.Posts)
|
||||
|
||||
arn.SortPostsLatestLast(replies)
|
||||
|
||||
// Benchmark
|
||||
// for i := 0; i < 7; i++ {
|
||||
// replies = append(replies, replies...)
|
||||
// }
|
||||
|
||||
if filterErr != nil {
|
||||
return ctx.Error(500, "Error fetching thread replies", err)
|
||||
if getErr != nil {
|
||||
return ctx.Error(http.StatusInternalServerError, "Could not retrieve posts", getErr)
|
||||
}
|
||||
|
||||
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))
|
||||
}
|
||||
|
29
patches/post-texts/main.go
Normal file
29
patches/post-texts/main.go
Normal 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)
|
||||
}
|
||||
}
|
34
patches/thread-posts/main.go
Normal file
34
patches/thread-posts/main.go
Normal 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)
|
||||
}
|
||||
}
|
@ -40,6 +40,9 @@ nav-link-hover-slide-color = rgb(248, 165, 130)
|
||||
// nav-link-color = rgb(160, 160, 160)
|
||||
// nav-link-hover-color = rgb(80, 80, 80)
|
||||
|
||||
// Loading animation
|
||||
loading-anim-color = nav-link-hover-slide-color
|
||||
|
||||
// Shadow
|
||||
shadow-light = 4px 4px 8px rgba(0, 0, 0, 0.05)
|
||||
shadow-medium = 6px 6px 12px rgba(0, 0, 0, 0.13)
|
||||
|
@ -17,7 +17,7 @@ loading-anim-size = 24px
|
||||
.sk-cube
|
||||
width 33.3%
|
||||
height 33.3%
|
||||
background-color main-color
|
||||
background-color loading-anim-color
|
||||
opacity 0.7
|
||||
border-radius 100%
|
||||
animation sk-pulse loading-anim-duration infinite linear
|
||||
|
Loading…
Reference in New Issue
Block a user