Changeset 423 in code for trunk/upstream.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/upstream.go

    r419 r423  
    8282        // set of LIST commands in progress, per downstream
    8383        pendingLISTDownstreamSet map[uint64]struct{}
    84 
    85         messageLoggers map[string]*messageLogger
    8684}
    8785
     
    183181                availableMemberships:     stdMemberships,
    184182                pendingLISTDownstreamSet: make(map[uint64]struct{}),
    185                 messageLoggers:           make(map[string]*messageLogger),
    186183        }
    187184        return uc, nil
     
    16121609
    16131610func (uc *upstreamConn) appendLog(entity string, msg *irc.Message) {
    1614         if uc.srv.LogPath == "" {
     1611        if uc.user.msgStore == nil {
    16151612                return
    1616         }
    1617 
    1618         ml, ok := uc.messageLoggers[entity]
    1619         if !ok {
    1620                 ml = newMessageLogger(uc.network, entity)
    1621                 uc.messageLoggers[entity] = ml
    16221613        }
    16231614
     
    16291620        history, ok := uc.network.history[entity]
    16301621        if !ok {
    1631                 lastID, err := lastMsgID(uc.network, entity, time.Now())
     1622                lastID, err := uc.user.msgStore.LastMsgID(uc.network, entity, time.Now())
    16321623                if err != nil {
    16331624                        uc.logger.Printf("failed to log message: failed to get last message ID: %v", err)
     
    16531644        }
    16541645
    1655         msgID, err := ml.Append(msg)
     1646        msgID, err := uc.user.msgStore.Append(uc.network, entity, msg)
    16561647        if err != nil {
    16571648                uc.logger.Printf("failed to log message: %v", err)
Note: See TracChangeset for help on using the changeset viewer.