Changeset 423 in code for trunk/downstream.go


Ignore:
Timestamp:
Oct 25, 2020, 4:47:38 PM (5 years ago)
Author:
contact
Message:

Add message store abstraction

Introduce a messageStore type, which will allow for multiple
implementations (e.g. in the DB or in-memory instead of on-disk).

The message store is per-user so that we don't need to deal with locking
and it's easier to implement per-user limits.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/downstream.go

    r421 r423  
    864864                        }
    865865
    866                         lastID, err := lastMsgID(net, target, time.Now())
     866                        lastID, err := dc.user.msgStore.LastMsgID(net, target, time.Now())
    867867                        if err != nil {
    868868                                dc.logger.Printf("failed to get last message ID: %v", err)
     
    877877
    878878func (dc *downstreamConn) sendNetworkHistory(net *network) {
    879         if dc.caps["draft/chathistory"] || dc.srv.LogPath == "" {
     879        if dc.caps["draft/chathistory"] || dc.user.msgStore == nil {
    880880                return
    881881        }
     
    891891
    892892                limit := 4000
    893                 history, err := loadHistoryLatestID(net, target, lastDelivered, limit)
     893                history, err := dc.user.msgStore.LoadLatestID(net, target, lastDelivered, limit)
    894894                if err != nil {
    895895                        dc.logger.Printf("failed to send implicit history for %q: %v", target, err)
     
    16021602                }
    16031603
    1604                 if dc.srv.LogPath == "" {
     1604                if dc.user.msgStore == nil {
    16051605                        return ircError{&irc.Message{
    16061606                                Command: irc.ERR_UNKNOWNCOMMAND,
     
    16421642                switch subcommand {
    16431643                case "BEFORE":
    1644                         history, err = loadHistoryBeforeTime(uc.network, entity, timestamp, limit)
     1644                        history, err = dc.user.msgStore.LoadBeforeTime(uc.network, entity, timestamp, limit)
    16451645                case "AFTER":
    1646                         history, err = loadHistoryAfterTime(uc.network, entity, timestamp, limit)
     1646                        history, err = dc.user.msgStore.LoadAfterTime(uc.network, entity, timestamp, limit)
    16471647                default:
    16481648                        // TODO: support LATEST, BETWEEN
Note: See TracChangeset for help on using the changeset viewer.