summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Manuel <nilslice@gmail.com>2016-10-29 01:33:33 -0700
committerSteve Manuel <nilslice@gmail.com>2016-10-29 01:33:33 -0700
commitb6eb040045fcfeb39dda4fcd440d2be184c8e715 (patch)
treef33b8374b9addf5f3a936ed0d555d0ea5d2904a1
parent30ea59f0d1cae4229490596efba22f9d9b298f4c (diff)
adding db/analytics init back in after reverting for debug
-rw-r--r--cmd/ponzu/main.go7
-rw-r--r--system/api/analytics/init.go6
-rw-r--r--system/api/external.go11
-rw-r--r--system/db/content.go11
-rw-r--r--system/db/init.go6
5 files changed, 21 insertions, 20 deletions
diff --git a/cmd/ponzu/main.go b/cmd/ponzu/main.go
index 2552256..234d3b6 100644
--- a/cmd/ponzu/main.go
+++ b/cmd/ponzu/main.go
@@ -11,6 +11,7 @@ import (
"github.com/bosssauce/ponzu/system/admin"
"github.com/bosssauce/ponzu/system/api"
+ "github.com/bosssauce/ponzu/system/api/analytics"
"github.com/bosssauce/ponzu/system/db"
"github.com/bosssauce/ponzu/system/tls"
)
@@ -169,10 +170,10 @@ func main() {
case "serve", "s":
db.Init()
- // defer db.Close()
+ defer db.Close()
- // analytics.Init()
- // defer analytics.Close()
+ analytics.Init()
+ defer analytics.Close()
if len(args) > 1 {
services := strings.Split(args[1], ",")
diff --git a/system/api/analytics/init.go b/system/api/analytics/init.go
index c04a7f2..c351bed 100644
--- a/system/api/analytics/init.go
+++ b/system/api/analytics/init.go
@@ -4,7 +4,6 @@
package analytics
import (
- "fmt"
"log"
"net/http"
"strings"
@@ -55,13 +54,12 @@ func Close() {
// Init creates a db connection, should run an initial prune of old data, and
// sets up the queue/batching channel
func Init() {
- store, err := bolt.Open("analytics.db", 0666, nil)
+ var err error
+ store, err = bolt.Open("analytics.db", 0666, nil)
if err != nil {
log.Fatalln(err)
}
- fmt.Println("analytics", store)
-
recordChan = make(chan apiRequest, 1024*128)
go serve()
diff --git a/system/api/external.go b/system/api/external.go
index 0da7eac..a65618b 100644
--- a/system/api/external.go
+++ b/system/api/external.go
@@ -8,12 +8,21 @@ import (
"github.com/bosssauce/ponzu/system/db"
)
-// Externalable accepts or rejects external POST requests to /external/posts?type=Review
+// Externalable accepts or rejects external POST requests to endpoints such as:
+// /external/posts?type=Review
type Externalable interface {
// Accepts determines whether a type will allow external submissions
Accepts() bool
}
+// Mergeable allows external post content to be approved and published through
+// the public-facing API
+type Mergeable interface {
+ // Approve copies an external post to the internal collection and triggers
+ // a re-sort of its content type posts
+ Approve() error
+}
+
func externalPostsHandler(res http.ResponseWriter, req *http.Request) {
if req.Method != http.MethodPost {
res.WriteHeader(http.StatusMethodNotAllowed)
diff --git a/system/db/content.go b/system/db/content.go
index 6e70c1b..8eb42b3 100644
--- a/system/db/content.go
+++ b/system/db/content.go
@@ -202,8 +202,8 @@ func ContentAll(namespace string) [][]byte {
store.View(func(tx *bolt.Tx) error {
b := tx.Bucket([]byte(namespace))
- len := b.Stats().KeyN
- posts = make([][]byte, 0, len)
+ numKeys := b.Stats().KeyN
+ posts = make([][]byte, 0, numKeys)
b.ForEach(func(k, v []byte) error {
posts = append(posts, v)
@@ -224,7 +224,7 @@ func SortContent(namespace string) {
all := ContentAll(namespace)
var posts sortablePosts
- // decode each (json) into Editable
+ // decode each (json) into type to then sort
for i := range all {
j := all[i]
post := content.Types[namespace]()
@@ -243,11 +243,6 @@ func SortContent(namespace string) {
// store in <namespace>_sorted bucket, first delete existing
err := store.Update(func(tx *bolt.Tx) error {
- err := tx.DeleteBucket([]byte(namespace + "_sorted"))
- if err != nil {
- return err
- }
-
b, err := tx.CreateBucket([]byte(namespace + "_sorted"))
if err != nil {
err := tx.Rollback()
diff --git a/system/db/init.go b/system/db/init.go
index 0c3c887..92fa908 100644
--- a/system/db/init.go
+++ b/system/db/init.go
@@ -2,7 +2,6 @@ package db
import (
"encoding/json"
- "fmt"
"log"
"github.com/bosssauce/ponzu/content"
@@ -25,13 +24,12 @@ func Close() {
// Init creates a db connection, initializes db with required info, sets secrets
func Init() {
- store, err := bolt.Open("system.db", 0666, nil)
+ var err error
+ store, err = bolt.Open("system.db", 0666, nil)
if err != nil {
log.Fatalln(err)
}
- fmt.Println("system", store)
-
err = store.Update(func(tx *bolt.Tx) error {
// initialize db with all content type buckets & sorted bucket for type
for t := range content.Types {