Logging removed
This commit is contained in:
parent
dd7550dffb
commit
ef23d9e45f
3
NOTES.md
3
NOTES.md
|
@ -1,8 +1,5 @@
|
||||||
# Notes
|
# Notes
|
||||||
|
|
||||||
## Subscriptions
|
|
||||||
- TODO: remove all logger lines
|
|
||||||
|
|
||||||
## Issues
|
## Issues
|
||||||
- URL for each tab should not be stored as a string - in the current code there's lots of reparsing the URL
|
- URL for each tab should not be stored as a string - in the current code there's lots of reparsing the URL
|
||||||
|
|
||||||
|
|
11
amfora.go
11
amfora.go
|
@ -7,7 +7,6 @@ import (
|
||||||
"github.com/makeworld-the-better-one/amfora/client"
|
"github.com/makeworld-the-better-one/amfora/client"
|
||||||
"github.com/makeworld-the-better-one/amfora/config"
|
"github.com/makeworld-the-better-one/amfora/config"
|
||||||
"github.com/makeworld-the-better-one/amfora/display"
|
"github.com/makeworld-the-better-one/amfora/display"
|
||||||
"github.com/makeworld-the-better-one/amfora/logger"
|
|
||||||
"github.com/makeworld-the-better-one/amfora/subscriptions"
|
"github.com/makeworld-the-better-one/amfora/subscriptions"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -18,10 +17,10 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
err := logger.Init()
|
// err := logger.Init()
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
panic(err)
|
// panic(err)
|
||||||
}
|
// }
|
||||||
|
|
||||||
if len(os.Args) > 1 {
|
if len(os.Args) > 1 {
|
||||||
if os.Args[1] == "--version" || os.Args[1] == "-v" {
|
if os.Args[1] == "--version" || os.Args[1] == "-v" {
|
||||||
|
@ -40,7 +39,7 @@ func main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
err = config.Init()
|
err := config.Init()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "Config error: %v\n", err)
|
fmt.Fprintf(os.Stderr, "Config error: %v\n", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
|
|
@ -12,7 +12,6 @@ import (
|
||||||
"github.com/gdamore/tcell"
|
"github.com/gdamore/tcell"
|
||||||
"github.com/makeworld-the-better-one/amfora/cache"
|
"github.com/makeworld-the-better-one/amfora/cache"
|
||||||
"github.com/makeworld-the-better-one/amfora/config"
|
"github.com/makeworld-the-better-one/amfora/config"
|
||||||
"github.com/makeworld-the-better-one/amfora/logger"
|
|
||||||
"github.com/makeworld-the-better-one/amfora/renderer"
|
"github.com/makeworld-the-better-one/amfora/renderer"
|
||||||
"github.com/makeworld-the-better-one/amfora/structs"
|
"github.com/makeworld-the-better-one/amfora/structs"
|
||||||
"github.com/makeworld-the-better-one/amfora/subscriptions"
|
"github.com/makeworld-the-better-one/amfora/subscriptions"
|
||||||
|
@ -34,8 +33,6 @@ func toLocalDay(t time.Time) time.Time {
|
||||||
|
|
||||||
// Subscriptions displays the subscriptions page on the current tab.
|
// Subscriptions displays the subscriptions page on the current tab.
|
||||||
func Subscriptions(t *tab, u string) string {
|
func Subscriptions(t *tab, u string) string {
|
||||||
logger.Log.Println("display.Subscriptions called")
|
|
||||||
|
|
||||||
pageN := 0 // Pages are zero-indexed internally
|
pageN := 0 // Pages are zero-indexed internally
|
||||||
|
|
||||||
// Correct URL if query string exists
|
// Correct URL if query string exists
|
||||||
|
@ -69,14 +66,11 @@ func Subscriptions(t *tab, u string) string {
|
||||||
// Retrieve cached version if there hasn't been any updates
|
// Retrieve cached version if there hasn't been any updates
|
||||||
p, ok := cache.GetPage(u)
|
p, ok := cache.GetPage(u)
|
||||||
if subscriptionPageUpdated[pageN].After(subscriptions.LastUpdated) && ok {
|
if subscriptionPageUpdated[pageN].After(subscriptions.LastUpdated) && ok {
|
||||||
logger.Log.Println("using cached subscriptions page")
|
|
||||||
setPage(t, p)
|
setPage(t, p)
|
||||||
t.applyBottomBar()
|
t.applyBottomBar()
|
||||||
return u
|
return u
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.Log.Println("started rendering subscriptions page")
|
|
||||||
|
|
||||||
pe := subscriptions.GetPageEntries()
|
pe := subscriptions.GetPageEntries()
|
||||||
|
|
||||||
// Figure out where the entries for this page start, if at all.
|
// Figure out where the entries for this page start, if at all.
|
||||||
|
@ -170,8 +164,6 @@ func Subscriptions(t *tab, u string) string {
|
||||||
|
|
||||||
subscriptionPageUpdated[pageN] = time.Now()
|
subscriptionPageUpdated[pageN] = time.Now()
|
||||||
|
|
||||||
logger.Log.Println("done rendering subscriptions page")
|
|
||||||
|
|
||||||
return u
|
return u
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -235,7 +227,6 @@ func manageSubscriptionQuery(t *tab, u string) {
|
||||||
// The subscribed arg specifies whether this feed/page is already
|
// The subscribed arg specifies whether this feed/page is already
|
||||||
// subscribed to.
|
// subscribed to.
|
||||||
func openSubscriptionModal(validFeed, subscribed bool) bool {
|
func openSubscriptionModal(validFeed, subscribed bool) bool {
|
||||||
logger.Log.Println("display.openFeedModal called")
|
|
||||||
// Reuses yesNoModal
|
// Reuses yesNoModal
|
||||||
|
|
||||||
if viper.GetBool("a-general.color") {
|
if viper.GetBool("a-general.color") {
|
||||||
|
@ -297,8 +288,6 @@ func getFeedFromPage(p *structs.Page) (*gofeed.Feed, bool) {
|
||||||
//
|
//
|
||||||
// Like addFeed, it should be called in a goroutine.
|
// Like addFeed, it should be called in a goroutine.
|
||||||
func addFeedDirect(u string, feed *gofeed.Feed, tracked bool) bool {
|
func addFeedDirect(u string, feed *gofeed.Feed, tracked bool) bool {
|
||||||
logger.Log.Println("display.addFeedDirect called")
|
|
||||||
|
|
||||||
if openSubscriptionModal(true, tracked) {
|
if openSubscriptionModal(true, tracked) {
|
||||||
err := subscriptions.AddFeed(u, feed)
|
err := subscriptions.AddFeed(u, feed)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -312,8 +301,6 @@ func addFeedDirect(u string, feed *gofeed.Feed, tracked bool) bool {
|
||||||
// addFeed goes through the process of subscribing to the current page/feed.
|
// addFeed goes through the process of subscribing to the current page/feed.
|
||||||
// It is the high-level way of doing it. It should be called in a goroutine.
|
// It is the high-level way of doing it. It should be called in a goroutine.
|
||||||
func addSubscription() {
|
func addSubscription() {
|
||||||
logger.Log.Println("display.addSubscription called")
|
|
||||||
|
|
||||||
t := tabs[curTab]
|
t := tabs[curTab]
|
||||||
p := t.page
|
p := t.page
|
||||||
|
|
||||||
|
|
|
@ -5,8 +5,6 @@ import (
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/makeworld-the-better-one/amfora/logger"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// This file contains funcs for creating PageEntries, which
|
// This file contains funcs for creating PageEntries, which
|
||||||
|
@ -42,8 +40,6 @@ func getURL(urls []string) string {
|
||||||
// so this function needs to be called again to get updates.
|
// so this function needs to be called again to get updates.
|
||||||
// It always returns sorted entries - by post time, from newest to oldest.
|
// It always returns sorted entries - by post time, from newest to oldest.
|
||||||
func GetPageEntries() *PageEntries {
|
func GetPageEntries() *PageEntries {
|
||||||
logger.Log.Println("subscriptions.GetPageEntries called")
|
|
||||||
|
|
||||||
var pe PageEntries
|
var pe PageEntries
|
||||||
|
|
||||||
data.RLock()
|
data.RLock()
|
||||||
|
|
|
@ -17,7 +17,6 @@ import (
|
||||||
|
|
||||||
"github.com/makeworld-the-better-one/amfora/client"
|
"github.com/makeworld-the-better-one/amfora/client"
|
||||||
"github.com/makeworld-the-better-one/amfora/config"
|
"github.com/makeworld-the-better-one/amfora/config"
|
||||||
"github.com/makeworld-the-better-one/amfora/logger"
|
|
||||||
"github.com/makeworld-the-better-one/go-gemini"
|
"github.com/makeworld-the-better-one/go-gemini"
|
||||||
"github.com/mmcdole/gofeed"
|
"github.com/mmcdole/gofeed"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
|
@ -90,8 +89,6 @@ func Init() error {
|
||||||
// IsSubscribed returns true if the URL is already subscribed to,
|
// IsSubscribed returns true if the URL is already subscribed to,
|
||||||
// whether a feed or page.
|
// whether a feed or page.
|
||||||
func IsSubscribed(url string) bool {
|
func IsSubscribed(url string) bool {
|
||||||
logger.Log.Println("subscriptions.IsSubscribed called")
|
|
||||||
|
|
||||||
data.feedMu.RLock()
|
data.feedMu.RLock()
|
||||||
for u := range data.Feeds {
|
for u := range data.Feeds {
|
||||||
if url == u {
|
if url == u {
|
||||||
|
@ -114,8 +111,6 @@ func IsSubscribed(url string) bool {
|
||||||
// GetFeed returns a Feed object and a bool indicating whether the passed
|
// GetFeed returns a Feed object and a bool indicating whether the passed
|
||||||
// content was actually recognized as a feed.
|
// content was actually recognized as a feed.
|
||||||
func GetFeed(mediatype, filename string, r io.Reader) (*gofeed.Feed, bool) {
|
func GetFeed(mediatype, filename string, r io.Reader) (*gofeed.Feed, bool) {
|
||||||
logger.Log.Println("subscriptions.GetFeed called")
|
|
||||||
|
|
||||||
if r == nil {
|
if r == nil {
|
||||||
return nil, false
|
return nil, false
|
||||||
}
|
}
|
||||||
|
@ -135,22 +130,17 @@ func GetFeed(mediatype, filename string, r io.Reader) (*gofeed.Feed, bool) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func writeJSON() error {
|
func writeJSON() error {
|
||||||
logger.Log.Println("subscriptions.writeJSON called")
|
|
||||||
|
|
||||||
writeMu.Lock()
|
writeMu.Lock()
|
||||||
defer writeMu.Unlock()
|
defer writeMu.Unlock()
|
||||||
|
|
||||||
data.Lock()
|
data.Lock()
|
||||||
logger.Log.Println("subscriptions.writeJSON acquired data lock")
|
|
||||||
jsonBytes, err := json.MarshalIndent(&data, "", " ")
|
jsonBytes, err := json.MarshalIndent(&data, "", " ")
|
||||||
data.Unlock()
|
data.Unlock()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Log.Println("subscriptions.writeJSON error", err)
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
err = ioutil.WriteFile(config.SubscriptionPath, jsonBytes, 0666)
|
err = ioutil.WriteFile(config.SubscriptionPath, jsonBytes, 0666)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Log.Println("subscriptions.writeJSON error", err)
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -161,8 +151,6 @@ func writeJSON() error {
|
||||||
// It can be used to update a feed for a URL, although the package
|
// It can be used to update a feed for a URL, although the package
|
||||||
// will handle that on its own.
|
// will handle that on its own.
|
||||||
func AddFeed(url string, feed *gofeed.Feed) error {
|
func AddFeed(url string, feed *gofeed.Feed) error {
|
||||||
logger.Log.Println("subscriptions.AddFeed called")
|
|
||||||
|
|
||||||
if feed == nil {
|
if feed == nil {
|
||||||
panic("feed is nil")
|
panic("feed is nil")
|
||||||
}
|
}
|
||||||
|
@ -211,8 +199,6 @@ func AddFeed(url string, feed *gofeed.Feed) error {
|
||||||
// It can be used to update the page as well, although the package
|
// It can be used to update the page as well, although the package
|
||||||
// will handle that on its own.
|
// will handle that on its own.
|
||||||
func AddPage(url string, r io.Reader) error {
|
func AddPage(url string, r io.Reader) error {
|
||||||
logger.Log.Println("subscriptions.AddPage called")
|
|
||||||
|
|
||||||
if r == nil {
|
if r == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -247,8 +233,6 @@ func AddPage(url string, r io.Reader) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func updateFeed(url string) error {
|
func updateFeed(url string) error {
|
||||||
logger.Log.Println("subscriptions.updateFeed called")
|
|
||||||
|
|
||||||
res, err := client.Fetch(url)
|
res, err := client.Fetch(url)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if res != nil {
|
if res != nil {
|
||||||
|
@ -274,8 +258,6 @@ func updateFeed(url string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func updatePage(url string) error {
|
func updatePage(url string) error {
|
||||||
logger.Log.Println("subscriptions.updatePage called")
|
|
||||||
|
|
||||||
res, err := client.Fetch(url)
|
res, err := client.Fetch(url)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if res != nil {
|
if res != nil {
|
||||||
|
@ -295,8 +277,6 @@ func updatePage(url string) error {
|
||||||
// updateAll updates all subscriptions using workers.
|
// updateAll updates all subscriptions using workers.
|
||||||
// It only returns once all the workers are done.
|
// It only returns once all the workers are done.
|
||||||
func updateAll() {
|
func updateAll() {
|
||||||
logger.Log.Println("subscriptions.updateAll called")
|
|
||||||
|
|
||||||
// TODO: Is two goroutines the right amount?
|
// TODO: Is two goroutines the right amount?
|
||||||
|
|
||||||
worker := func(jobs <-chan [2]string, wg *sync.WaitGroup) {
|
worker := func(jobs <-chan [2]string, wg *sync.WaitGroup) {
|
||||||
|
@ -333,9 +313,7 @@ func updateAll() {
|
||||||
for w := 0; w < numWorkers; w++ {
|
for w := 0; w < numWorkers; w++ {
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
go func(i int) {
|
go func(i int) {
|
||||||
logger.Log.Println("started worker", i)
|
|
||||||
worker(jobs, &wg)
|
worker(jobs, &wg)
|
||||||
logger.Log.Println("ended worker", i)
|
|
||||||
}(w)
|
}(w)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue