compact

package
v0.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 21, 2026 License: Apache-2.0 Imports: 11 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package compact is "etherpad-go compact": etherpad-lite's bin/compactPad, bin/compactAllPads and bin/compactStalePads as a command of the binary.

It talks to the running server through its HTTP API (listAllPads, getLastEdited, getRevisionsCount, compactPad), as etherpad-lite's scripts do: the server holds pads in memory, so changing their history behind its back in the database would leave it with a stale copy. Compacting is destructive; export what you cannot lose as .etherpad first.

Index

Constants

View Source
const MaxOlderThanDays = 100_000

MaxOlderThanDays is the most days --older-than takes: a time.Duration holds about 106751 days, beyond that the cutoff would wrap into the future and select freshly edited pads.

Variables

This section is empty.

Functions

func Main

func Main(args []string, out, errOut io.Writer, api API) int

Main is RunFromCLI without exiting; api replaces the HTTP API in tests.

func RunFromCLI

func RunFromCLI(args []string)

RunFromCLI runs "etherpad-go compact" and exits: 0 when every pad was compacted, 1 when one failed, 2 on a usage error.

Types

type API

type API interface {
	ListAllPads() ([]string, error)
	// GetLastEdited is the time of the pad's last edit, in milliseconds.
	GetLastEdited(padID string) (int64, error)
	// GetRevisionsCount is the pad's head revision number.
	GetRevisionsCount(padID string) (int, error)
	// CompactPad collapses the history, or keeps its last keep revisions.
	CompactPad(padID string, keep *int) error
}

API is the part of the HTTP API the command uses.

type HTTPAPI

type HTTPAPI struct {
	BaseURL string // e.g. http://localhost:9001
	APIKey  string
	Client  *http.Client
	// contains filtered or unexported fields
}

HTTPAPI calls the server's HTTP API (/api/<version>/<function>) with an API key.

func (*HTTPAPI) CompactPad

func (h *HTTPAPI) CompactPad(padID string, keep *int) error

func (*HTTPAPI) GetLastEdited

func (h *HTTPAPI) GetLastEdited(padID string) (int64, error)

func (*HTTPAPI) GetRevisionsCount

func (h *HTTPAPI) GetRevisionsCount(padID string) (int, error)

func (*HTTPAPI) ListAllPads

func (h *HTTPAPI) ListAllPads() ([]string, error)

type Options

type Options struct {
	// Pads to compact; empty: every pad of the instance.
	Pads []string
	// OlderThanDays > 0 compacts only pads not edited for that many days
	// (bin/compactStalePads).
	OlderThanDays int
	// Keep the last Keep revisions; nil collapses all history.
	Keep   *int
	DryRun bool
}

Options of a run.

type Report

type Report struct {
	Total, Selected, OK, Failed, SkippedFresh int
	RevsBefore, RevsAfter                     int
}

Report counts what a run did. Revisions count the head plus one, as etherpad-lite's scripts report them.

func Run

func Run(api API, opts Options, out, errOut io.Writer, now func() time.Time) Report

Run compacts the pads opts selects. A pad that fails is logged and counted; the run goes on.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL