Repository: codenotary/immudb
File: pkg/server/sessions/session.go (Go)

Code before:
See the License for the specific language governing permissions and
limitations under the License.
*/

package sessions

import (
	"context"
	"sync"
	"time"

	"github.com/codenotary/immudb/embedded/cache"
	"github.com/codenotary/immudb/embedded/document"
	"github.com/codenotary/immudb/embedded/sql"

	"github.com/codenotary/immudb/embedded/multierr"
	"github.com/codenotary/immudb/pkg/api/protomodel"
	"github.com/codenotary/immudb/pkg/auth"
	"github.com/codenotary/immudb/pkg/database"
	"github.com/codenotary/immudb/pkg/errors"
	"github.com/codenotary/immudb/pkg/logger"
	"github.com/codenotary/immudb/pkg/server/sessions/internal/transactions"
	"google.golang.org/grpc/metadata"
)

const DefaultMaxDocumentReadersCacheSize = 5

var (
	ErrPaginatedDocumentReaderNotFound = errors.New("document reader not found")
)

type PaginatedDocumentReader struct {
	Reader         document.DocumentReader // reader to read from
	Query          *protomodel.Query
	LastPageNumber uint32 // last read page number
	LastPageSize   uint32 // number of items per page
}

type Session struct {
	mux              sync.RWMutex
	id               string
	user             *auth.User
	database         database.DB
	creationTime     time.Time
	lastActivityTime time.Time
	transactions     map[string]transactions.Transaction
	documentReaders  *cache.LRUCache // track searchID to sql.RowReader objects
	log              logger.Logger
}

func NewSession(sessionID string, user *auth.User, db database.DB, log logger.Logger) *Session {

Review comment (performance):
```suggestion
const DefaultMaxDocumentReadersCacheSize = 1
```

Code after:
See the License for the specific language governing permissions and
limitations under the License.
*/

package sessions

import (
	"context"
	"sync"
	"time"

	"github.com/codenotary/immudb/embedded/cache"
	"github.com/codenotary/immudb/embedded/document"
	"github.com/codenotary/immudb/embedded/sql"

	"github.com/codenotary/immudb/embedded/multierr"
	"github.com/codenotary/immudb/pkg/api/protomodel"
	"github.com/codenotary/immudb/pkg/auth"
	"github.com/codenotary/immudb/pkg/database"
	"github.com/codenotary/immudb/pkg/errors"
	"github.com/codenotary/immudb/pkg/logger"
	"github.com/codenotary/immudb/pkg/server/sessions/internal/transactions"
	"google.golang.org/grpc/metadata"
)

// DefaultMaxDocumentReadersCacheSize is the default maximum number of document readers to keep in cache
const DefaultMaxDocumentReadersCacheSize = 1

var (
	ErrPaginatedDocumentReaderNotFound = errors.New("document reader not found")
)

type PaginatedDocumentReader struct {
	Reader         document.DocumentReader // reader to read from
	Query          *protomodel.Query
	LastPageNumber uint32 // last read page number
	LastPageSize   uint32 // number of items per page
}

type Session struct {
	mux              sync.RWMutex
	id               string
	user             *auth.User
	database         database.DB
	creationTime     time.Time
	lastActivityTime time.Time
	transactions     map[string]transactions.Transaction
	documentReaders  *cache.LRUCache // track searchID to document.DocumentReader
	log              logger.Logger
}