forked from piraces/rsslay
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor rsslay to proactively retrieve feeds (#21)
Goals: - Download data in the background to always be able to return data quickly. - Done. - Make the project more composable e.g. separate out markdown and html processing from constructing nostr events. - Created clear adapter/app/domain layers. Didn't fix everything to keep the pull request small. - Make testing easier. - Testing the domain layer is easy now. - Eliminate the bug which causes the feed to not be updated under some circumstances. - Unclear. Maybe we need to remove caching altogether, it is not really useful right now. What has been done: - http handlers no longer contain core domain logic - http handlers no longer have direct access to the database - http handlers no longer misuse the same types for database queries and template rendering - http handlers no longer have access to secrets - created an adapters layer which encapsulates database access - created an domain layer for data validation, more core logic needs to be moved there in the future - created an application layer to glue everything together - cleaned up duplicated calls to libraries to convert keys to the nip19 format in http handlers - cleaned up error handling logic in http handlers - saving feed definitions will no longer fail quietly in case of database errors - fixed nonsensical error handling when saving feed definitions - events are properly retrieved in a single place in the application layer and not from multiple places - removed duplicate code
- Loading branch information
Showing
24 changed files
with
1,280 additions
and
275 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/nbd-wtf/go-nostr" | ||
"github.com/piraces/rsslay/pkg/metrics" | ||
"github.com/piraces/rsslay/pkg/new/app" | ||
nostrdomain "github.com/piraces/rsslay/pkg/new/domain/nostr" | ||
"github.com/pkg/errors" | ||
) | ||
|
||
type store struct { | ||
app app.App | ||
} | ||
|
||
func newStore(app app.App) *store { | ||
return &store{app: app} | ||
} | ||
|
||
func (b store) Init() error { | ||
return nil | ||
} | ||
|
||
func (b store) SaveEvent(_ *nostr.Event) error { | ||
metrics.InvalidEventsRequests.Inc() | ||
return errors.New("blocked: we don't accept any events") | ||
} | ||
|
||
func (b store) DeleteEvent(_, _ string) error { | ||
metrics.InvalidEventsRequests.Inc() | ||
return errors.New("blocked: we can't delete any events") | ||
} | ||
|
||
func (b store) QueryEvents(libfilter *nostr.Filter) ([]nostr.Event, error) { | ||
metrics.QueryEventsRequests.Inc() | ||
|
||
filter := nostrdomain.NewFilter(libfilter) | ||
events, err := b.app.GetEvents.Handle(filter) | ||
if err != nil { | ||
return nil, errors.Wrap(err, "error getting events") | ||
} | ||
|
||
return b.toEvents(events), nil | ||
} | ||
|
||
func (b store) toEvents(events []nostrdomain.Event) []nostr.Event { | ||
var result []nostr.Event | ||
for _, event := range events { | ||
result = append(result, event.Libevent()) | ||
} | ||
return result | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.