feat: filter memos by attachments and images (#6492)

This commit is contained in:
Johnny
2026-10-22 18:58:45 +08:00
committed by GitHub
parent 008dded234
commit 9576bd53ac
78 changed files with 1182 additions and 62 deletions
+119 -38
View File
@@ -1,3 +1,5 @@
// Package memopayload computes the content-derived part of a memo payload and
// keeps stored payloads current when that computation changes.
package memopayload
import (
@@ -5,17 +7,31 @@ import (
"log/slog"
"github.com/pkg/errors"
"google.golang.org/protobuf/proto"
"github.com/usememos/memos/markdown"
storepb "github.com/usememos/memos/proto/gen/store"
"github.com/usememos/memos/store"
)
// Version identifies the content-derived part of a memo payload, the tags and
// property that RebuildMemoPayload takes from the Markdown extractor. Bump it
// whenever that output changes for existing content, so the server rebuilds
// every memo's payload once after upgrading.
//
// 1: Property.has_inline_image.
const Version = 1
// batchSize is how many memos the rebuild loads at a time.
const batchSize = 100
// Runner rebuilds stored memo payloads.
type Runner struct {
Store *store.Store
MarkdownService markdown.Service
}
// NewRunner returns a Runner over the store.
func NewRunner(store *store.Store, markdownService markdown.Service) *Runner {
return &Runner{
Store: store,
@@ -23,54 +39,119 @@ func NewRunner(store *store.Store, markdownService markdown.Service) *Runner {
}
}
// RunOnce rebuilds the payload of all memos.
func (r *Runner) RunOnce(ctx context.Context) {
// Process memos in batches to avoid loading all memos into memory at once
const batchSize = 100
offset := 0
processed := 0
// Backfill rebuilds every memo's content-derived payload once per Version.
// The version is recorded only after a pass in which every memo was written,
// so an interrupted or failed pass runs again on the next start. Rebuilding is
// idempotent, and each write is guarded against concurrent edits, so it is
// safe to run while the server takes traffic.
func (r *Runner) Backfill(ctx context.Context) error {
basicSetting, err := r.Store.GetInstanceBasicSetting(ctx)
if err != nil {
return errors.Wrap(err, "failed to get instance basic setting")
}
if basicSetting.PayloadVersion >= Version {
return nil
}
slog.Info("rebuilding memo payloads",
slog.Int("fromVersion", int(basicSetting.PayloadVersion)),
slog.Int("toVersion", Version))
if err := r.RunOnce(ctx); err != nil {
return err
}
for {
limit := batchSize
// Re-read: the cache hands out a shared value, and the setting may have
// changed during the pass.
basicSetting, err = r.Store.GetInstanceBasicSetting(ctx)
if err != nil {
return errors.Wrap(err, "failed to get instance basic setting")
}
updated := proto.CloneOf(basicSetting)
updated.PayloadVersion = Version
if _, err := r.Store.UpsertInstanceSetting(ctx, &storepb.InstanceSetting{
Key: storepb.InstanceSettingKey_BASIC,
Value: &storepb.InstanceSetting_BasicSetting{BasicSetting: updated},
}); err != nil {
return errors.Wrap(err, "failed to record memo payload version")
}
return nil
}
// RunOnce rebuilds the content-derived payload of every memo. It collects the
// memo IDs first, so memos created or deleted during the pass cannot shift the
// pages and skip a memo. Content that fails to parse is logged and skipped,
// since a retry cannot fix it; a failed write fails the pass after every memo
// has been tried.
func (r *Runner) RunOnce(ctx context.Context) error {
ids, err := r.listMemoIDs(ctx)
if err != nil {
return err
}
refreshed, skipped, failed := 0, 0, 0
for start := 0; start < len(ids); start += batchSize {
if err := ctx.Err(); err != nil {
return err
}
end := min(start+batchSize, len(ids))
memos, err := r.Store.ListMemos(ctx, &store.FindMemo{IDList: ids[start:end]})
if err != nil {
return errors.Wrap(err, "failed to list memos")
}
for _, memo := range memos {
data, err := r.MarkdownService.ExtractAll([]byte(memo.Content))
if err != nil {
slog.Warn("skipping memo payload rebuild", slog.Int("memoID", int(memo.ID)), slog.String("error", err.Error()))
skipped++
continue
}
if err := r.Store.RefreshMemoDerivedPayload(ctx, &store.RefreshMemoDerivedPayload{
ID: memo.ID,
Content: memo.Content,
Tags: data.Tags,
Property: data.Property,
}); err != nil {
if ctx.Err() != nil {
return ctx.Err()
}
slog.Error("failed to rebuild memo payload", slog.Int("memoID", int(memo.ID)), slog.String("error", err.Error()))
failed++
continue
}
refreshed++
}
}
slog.Info("rebuilt memo payloads",
slog.Int("refreshed", refreshed), slog.Int("skipped", skipped), slog.Int("failed", failed))
if failed > 0 {
return errors.Errorf("failed to rebuild %d memo payloads", failed)
}
return nil
}
func (r *Runner) listMemoIDs(ctx context.Context) ([]int32, error) {
ids := []int32{}
for offset := 0; ; offset += batchSize {
limit, pageOffset := batchSize, offset
memos, err := r.Store.ListMemos(ctx, &store.FindMemo{
Limit: &limit,
Offset: &offset,
ExcludeContent: true,
OrderByTimeAsc: true,
Limit: &limit,
Offset: &pageOffset,
})
if err != nil {
slog.Error("failed to list memos", "err", err)
return
return nil, errors.Wrap(err, "failed to list memo IDs")
}
// Break if no more memos
if len(memos) == 0 {
break
}
// Process batch
batchSuccessCount := 0
for _, memo := range memos {
if err := RebuildMemoPayload(ctx, memo, r.MarkdownService); err != nil {
slog.Error("failed to rebuild memo payload", "err", err, "memoID", memo.ID)
continue
}
if err := r.Store.UpdateMemo(ctx, &store.UpdateMemo{
ID: memo.ID,
Payload: memo.Payload,
}); err != nil {
slog.Error("failed to update memo", "err", err, "memoID", memo.ID)
continue
}
batchSuccessCount++
ids = append(ids, memo.ID)
}
if len(memos) < batchSize {
return ids, nil
}
processed += len(memos)
slog.Info("Processed memo batch", "batchSize", len(memos), "successCount", batchSuccessCount, "totalProcessed", processed)
// Move to next batch
offset += len(memos)
}
}
// RebuildMemoPayload sets the memo's tags and property from its content.
func RebuildMemoPayload(_ context.Context, memo *store.Memo, markdownService markdown.Service) error {
if memo.Payload == nil {
memo.Payload = &storepb.MemoPayload{}
+98
View File
@@ -0,0 +1,98 @@
package memopayload_test
import (
"context"
"testing"
"github.com/stretchr/testify/require"
"google.golang.org/protobuf/proto"
"github.com/usememos/memos/core/memopayload"
"github.com/usememos/memos/markdown"
storepb "github.com/usememos/memos/proto/gen/store"
"github.com/usememos/memos/store"
teststore "github.com/usememos/memos/store/test"
)
func TestBackfillRebuildsOncePerVersion(t *testing.T) {
ctx := context.Background()
st := teststore.NewTestingStore(ctx, t)
user, err := st.CreateUser(ctx, &store.User{Username: "payload-backfill", Role: store.RoleUser, PasswordHash: "hash"})
require.NoError(t, err)
// Payloads written before has_inline_image existed: the flag is missing.
location := &storepb.MemoPayload_Location{Placeholder: "Pier"}
external, err := st.CreateMemo(ctx, &store.Memo{
UID: "backfill-external-image", CreatorID: user.ID, Visibility: store.Private,
Content: "![view](https://example.com/view.jpg) #travel",
Payload: &storepb.MemoPayload{Tags: []string{"travel"}, Location: location},
})
require.NoError(t, err)
plain, err := st.CreateMemo(ctx, &store.Memo{
UID: "backfill-plain", CreatorID: user.ID, Visibility: store.Private,
Content: "no picture",
Payload: &storepb.MemoPayload{Property: &storepb.MemoPayload_Property{HasLink: true}},
})
require.NoError(t, err)
runner := memopayload.NewRunner(st, newMarkdownService())
require.NoError(t, runner.Backfill(ctx))
got, err := st.GetMemo(ctx, &store.FindMemo{ID: &external.ID})
require.NoError(t, err)
require.True(t, got.Payload.GetProperty().GetHasInlineImage())
require.Equal(t, []string{"travel"}, got.Payload.Tags)
require.Equal(t, "Pier", got.Payload.GetLocation().GetPlaceholder(), "the rebuild keeps the location")
got, err = st.GetMemo(ctx, &store.FindMemo{ID: &plain.ID})
require.NoError(t, err)
require.False(t, got.Payload.GetProperty().GetHasLink(), "stale flags are recomputed from content")
basic, err := st.GetInstanceBasicSetting(ctx)
require.NoError(t, err)
require.Equal(t, int32(memopayload.Version), basic.PayloadVersion)
require.NotEmpty(t, basic.SchemaVersion, "recording the version keeps the other basic setting fields")
// A recorded version skips the pass: a payload changed after it stays.
stale := &storepb.MemoPayload{}
require.NoError(t, st.UpdateMemo(ctx, &store.UpdateMemo{ID: external.ID, Payload: stale}))
require.NoError(t, runner.Backfill(ctx))
got, err = st.GetMemo(ctx, &store.FindMemo{ID: &external.ID})
require.NoError(t, err)
require.False(t, got.Payload.GetProperty().GetHasInlineImage())
// An older recorded version runs the pass again.
older, ok := proto.Clone(basic).(*storepb.InstanceBasicSetting)
require.True(t, ok)
older.PayloadVersion = memopayload.Version - 1
_, err = st.UpsertInstanceSetting(ctx, &storepb.InstanceSetting{
Key: storepb.InstanceSettingKey_BASIC,
Value: &storepb.InstanceSetting_BasicSetting{BasicSetting: older},
})
require.NoError(t, err)
require.NoError(t, runner.Backfill(ctx))
got, err = st.GetMemo(ctx, &store.FindMemo{ID: &external.ID})
require.NoError(t, err)
require.True(t, got.Payload.GetProperty().GetHasInlineImage())
}
func TestBackfillStopsOnCancel(t *testing.T) {
ctx := context.Background()
st := teststore.NewTestingStore(ctx, t)
user, err := st.CreateUser(ctx, &store.User{Username: "payload-cancel", Role: store.RoleUser, PasswordHash: "hash"})
require.NoError(t, err)
_, err = st.CreateMemo(ctx, &store.Memo{UID: "backfill-cancel", CreatorID: user.ID, Visibility: store.Private, Content: "x"})
require.NoError(t, err)
canceled, cancel := context.WithCancel(ctx)
cancel()
require.Error(t, memopayload.NewRunner(st, newMarkdownService()).Backfill(canceled))
basic, err := st.GetInstanceBasicSetting(ctx)
require.NoError(t, err)
require.Zero(t, basic.PayloadVersion, "an interrupted pass must not record the version")
}
// newMarkdownService matches the extensions the server uses.
func newMarkdownService() markdown.Service {
return markdown.NewService(markdown.WithTagExtension(), markdown.WithMentionExtension())
}
+4
View File
@@ -18,6 +18,10 @@ Drafts, merged but not yet released:
- [User usage limits](user-usage-limits.md)
Drafts, implemented but not yet merged:
- [Memo attachment and image filters](memo-attachment-filters.md)
Implemented and frozen:
- [API abuse controls](api-abuse-controls.md)
+252
View File
@@ -0,0 +1,252 @@
# Memo Attachment and Image Filters Design
Status: Draft (implemented, not yet merged)
Date: 2026-10-22
Existing domain language: [Memos context](../../CONTEXT.md)
Related: [Multi-Spaces](multi-spaces.md) for the memo list query shape, `filter/README.md` and `filter/MAINTENANCE.md` for the filter engine.
## Summary
Memos can be filtered by facts derived from their content: `has_link`, `has_code`, `has_task_list`, `has_incomplete_tasks`, and
`has_location`. There is no way to ask for memos that carry a file, or memos that show a picture, although both are among the most
common ways people recognise a memo they are looking for.
This design adds two filter fields:
- `has_attachments`: the memo has at least one bound attachment, of any type.
- `has_image`: the memo shows an image when rendered, either because its content contains a Markdown image or because an image file is
attached to it.
The two fields differ in where their truth lives, and the design keeps each fact in the one place that already owns it. Attachment
binding is a relation stored in `attachment.memo_id`, so both fields read it with an `EXISTS` subquery at query time. Markdown image
syntax is a content fact, so it becomes a new stored payload property, `has_inline_image`, computed by the same extractor that
computes `has_link`. Nothing about attachments is copied into the memo row, so there is nothing that can drift when an attachment is
added, moved, or deleted without the memo content changing.
Existing memos get the new property from a one-time background rebuild, gated by a payload version recorded in the instance basic
setting. The same gate serves every later change to what the extractor stores.
## Goals
- `has_attachments` and `has_image` work in every place a memo filter is accepted: the list API, saved Views, the web search box, and
the MCP memo listing.
- Both fields support the same grammar as `has_location`: bare, negated, and compared with `true` or `false`.
- Results are correct immediately after any attachment change, with no rebuild step and no eventual consistency.
- Existing memos match after upgrade without being edited, and the upgrade does not delay serving.
## Non-goals
- Counting attachments or filtering by attachment size, name, or storage type. The attachment list API already filters attachments
directly.
- Sorting memos by these fields. Filter fields are predicates only.
- Exposing `has_image` as a memo property on the API. Clients that render a memo already hold its attachment list and can derive it.
- Treating raw HTML `<img>` tags as images. The Markdown extractor already rejects managed attachment references in raw HTML, and the
renderer sanitises them; content that cannot show an image does not count as having one.
- A new database index. See [Query cost](#query-cost).
## Behavior
### `has_attachments`
True when at least one row in `attachment` has `memo_id` equal to the memo's id. Comments are memos and can have attachments, so a
comment with a file matches like any other memo. An attachment that is uploaded but not yet bound to a memo matches nothing.
A managed image embedded in the content, `![alt](/file/attachments/<uid>)`, is always backed by a bound attachment: the server refuses
to save content that references a managed attachment that is not bound to the memo, and requires that attachment to have an `image/*`
type. `has_attachments` therefore already covers inline managed images, and needs no content half.
### `has_image`
True when either of the following holds:
1. The content contains a Markdown image. This covers managed attachment images and external images alike, since both render as a
picture. Images inside code spans and code blocks do not count; the parser does not produce image nodes there.
2. At least one bound attachment has a MIME type starting with `image/`, case-insensitively. This covers the common flow of uploading
a photo without referencing it in the text; such attachments render in the memo's attachment strip.
From the user's side there is one question, "does this memo show a picture", and one field answers it. The two sources are an
implementation detail that the filter renderer hides.
### Grammar
Both fields are booleans with the comparison rules of `has_location`:
| Expression | Meaning |
| --- | --- |
| `has_image` | memos that show an image |
| `!has_image` | memos that do not |
| `has_image == true`, `has_image != false` | same as the bare form |
| `has_image == false`, `has_image != true` | same as the negated form |
| `has_attachments && !has_image` | memos with files but no picture |
Other operators are rejected at parse time, as they are for the existing boolean fields.
## Storage
### Stored payload: `has_inline_image`
`MemoPayload.Property` in `proto/store/memo.proto` gains `bool has_inline_image = 6`. The Markdown extractor sets it when it visits an
image node, in both `ExtractAll` and `ExtractProperties`, next to `has_link`. Like the other flags it is omitted from the stored JSON
when false, so a missing key reads as false.
The flag is named for what it measures, Markdown image syntax, and not `has_image`, because the stored property is also published on
the API as `Memo.property` and every field there is documented as a fact about the content. A stored `has_image` that is false on a
memo with three uploaded photos would be misleading, and would invite someone to "simplify" the filter down to the stored flag.
`Memo.Property` in `proto/api/memo_service.proto` gains the matching `bool has_inline_image = 6`, documented as "Whether the content
contains a Markdown image." The API `Property` message stays a pure content summary. The change is additive, so
`proto/api/CHANGELOG.md` has no entry.
### Payload version
`InstanceBasicSetting` in `proto/store/instance_setting.proto` gains `int32 payload_version = 3`: the version every memo's
content-derived payload has been rebuilt to. The current version is the constant `memopayload.Version` in `core/memopayload`, next to
the rebuild that consumes it. It is `1`, for `has_inline_image`. Every later change to what the extractor stores for existing content
bumps it. The constant lives in `core/memopayload` and not in `markdown`, because the Markdown engine knows nothing about how memos are
stored or upgraded.
There is no other schema change and no migration file.
## Filter rendering
The filter engine gains one field kind, `FieldKindExists`, for a boolean derived from the presence of related rows. A field of this
kind carries a `Related` description:
- `Table`, `ForeignKey`, and `Owner`: the related table, its column that holds the owner's key, and the outer column it refers to,
`memo.id`.
- optionally `PrefixColumn` and `Prefix`: keep only related rows whose column starts with a schema constant, ignoring case. The
renderer rejects a prefix containing quotes or `LIKE` wildcards.
It may also carry a `JSONPath`: a payload boolean that is OR-ed with the subquery.
The renderer produces `EXISTS (SELECT 1 FROM <table> WHERE <table>.<fk> = memo.id [AND LOWER(<table>.<col>) LIKE '<prefix>%'])`, with
dialect quoting through the existing column helpers. When a `JSONPath` is set, the result is `(<json bool predicate> OR EXISTS (...))`,
using the existing `jsonBoolPredicate` helper so the payload half keeps the dialect-specific handling of a missing key or a NULL
payload. Negation and `== false` wrap the whole expression in `NOT (...)`, which is already how `has_location` is rendered. Both halves
are two-valued, so a memo with no payload and no attachments is correctly excluded or included. The SQL carries no bound arguments.
The two fields:
| Field | Related | Prefix | JSONPath |
| --- | --- | --- | --- |
| `has_attachments` | `attachment.memo_id` = `memo.id` | none | none |
| `has_image` | `attachment.memo_id` = `memo.id` | `type` starts with `image/` | `property.hasInlineImage` |
`LOWER` keeps the MIME check case-insensitive on SQLite and PostgreSQL, where `LIKE` is case-sensitive; on MySQL it is harmless.
Both subquery contexts that compile memo filters select `FROM memo`: the memo list, and the memo-relation listing that wraps the
filter in `memo_id IN (SELECT id FROM memo WHERE ...)`. The correlated `memo.id` resolves correctly in both.
### Query cost
`attachment` is indexed on `creator_id` only, so the subquery finds a memo's attachments without an index on `memo_id`. PostgreSQL and
MySQL 8 plan a correlated `EXISTS` like this as a semi-join and can hash the attachment table once; SQLite can build a transient
automatic index for the subquery. An index on `attachment(memo_id)` was considered and deferred: it would also speed up the per-page
attachment load that the memo list already performs, and should be added in its own change if list latency with these filters is
measured to need it.
## Backfill
`has_attachments` needs none, and `has_image` matches every memo with an image attachment from the first request after upgrade.
`has_inline_image` is stored, so memos saved before the upgrade lack it until their payload is rebuilt. Only memos whose only image is
an external URL are affected, because managed inline images are bound attachments and already match through the subquery. The
rebuild closes that gap.
**When it runs.** After the HTTP server starts listening, the server starts `memopayload.Runner.Backfill` in the background. It reads
the basic setting and returns at once when `payload_version` is at least `memopayload.Version`, so a normal start does no work. A fresh
install runs the pass over zero memos and records the version.
**What it writes.** For each memo, the runner extracts tags and property from the content and calls
`store.RefreshMemoDerivedPayload`. That write replaces only `$.tags` and `$.property` inside the payload JSON, through `JSON_SET` on
SQLite and MySQL and `jsonb_set` on PostgreSQL, and only `WHERE content = ?` with the content the values were computed from. On MySQL
the comparison is binary, so a case-insensitive collation cannot match an edit that only changed case. The location and every other
payload key stay as stored, and `updated_ts` does not change, so the rebuild never reorders recently updated memos. A memo that a user
edits during the pass is left alone; the edit already wrote a current payload. This guard is why the pass can run while the server
takes traffic. A plain `UpdateMemo` would write the whole payload read moments earlier, and could undo a concurrent tag or location
change.
**Coverage.** The runner first collects every memo ID in creation order, then loads and rebuilds memos in batches of 100 by ID list.
Memos created or deleted during the pass cannot shift a page boundary and skip a memo; memos created during the pass already carry the
current payload.
**Recording the version.** The version is written to the basic setting only after a pass in which every memo was written. A failed
write fails the pass after all memos have been tried, and the next start runs it again. Content the extractor cannot parse is logged
and skipped, since a retry cannot fix it and must not make every start repeat the pass. The runner clones the cached basic setting
before writing, so the schema version and secret are kept. On shutdown the server cancels the pass and waits for it before closing the
store; a canceled pass does not record the version. Rebuilding is idempotent, so a repeated or concurrent pass, for example from two
replicas, is harmless.
## Surfaces
| Surface | Change |
| --- | --- |
| `proto/store/memo.proto`, `proto/api/memo_service.proto` | `has_inline_image = 6` on both `Property` messages; the `ListMemosRequest.filter` field list names `has_attachments` and `has_image` |
| `proto/store/instance_setting.proto` | `payload_version = 3` on `InstanceBasicSetting` |
| `markdown/markdown.go` | set `HasInlineImage` on image nodes in both extraction walks |
| `server/api/memo_service_converter.go` | map the property to the API |
| `filter/schema.go`, `filter/render.go`, `filter/README.md`, `filter/MAINTENANCE.md` | `FieldKindExists`, `RelatedRows`, the two fields, and the documented grammar |
| `store/memo.go`, `store/driver.go`, `store/db/{sqlite,mysql,postgres}/memo.go` | `RefreshMemoDerivedPayload` |
| `core/memopayload/runner.go` | `Version`, `Backfill`, and the ID-first `RunOnce` |
| `server/server.go` | start the backfill after listening; cancel and wait for it on shutdown |
| `web/src/contexts/MemoFilterContext.tsx`, `web/src/components/MemoFilters.tsx`, `web/src/hooks/useMemoFilters.ts` | `property.hasAttachments` and `property.hasImage` factors with chips, following the `property.hasLocation` precedent for a non-content field |
| `web/src/pages/MemoViews.tsx` | two view examples, "With attachments" (`has_attachments`) and "Photos" (`has_image`), and both names in the field reference list |
| `web/src/locales/*.json` | `memo.filters.has-attachments` and `memo.filters.has-image` in every locale, as the parity test requires |
The MCP tools are generated from the OpenAPI document, so the updated filter description reaches the MCP memo listing with no change
there. The web chips exist for parity with the other property factors; today nothing in the UI sets those factors, and users reach
the fields through the search box and saved Views. A sidebar entry point is a separate UI decision.
## Verification
| Check | Covers |
| --- | --- |
| `go test ./markdown/... -run TestExtractInlineImage` | the flag for external, managed, reference-style, and linked images; not for code or raw HTML; both walks agree |
| `go test ./filter/...` | per-dialect goldens for the six comparison forms of both fields, rejected operators, and a SQLite behavioural test over real `memo` and `attachment` tables |
| `DRIVER=<driver> go test ./store/test/ -run TestRefreshMemoDerivedPayload` | the guarded write on SQLite, MySQL, and PostgreSQL: location and `updated_ts` kept, a case-only content edit not matched, the refreshed flag visible to `has_image` |
| `go test ./core/memopayload/...` | the version gate: rebuild once, skip when recorded, rerun when older, keep other basic setting fields, no version on cancel |
| `cd web && pnpm lint && pnpm test` | factors, chips, view examples, and locale parity |
## Alternatives considered
**Store `has_attachments` in the payload next to `has_link`.** Rejected. The payload properties are rebuilt from content, in one
place, on content writes. Attachment binding changes in at least six places that never touch content: setting a memo's attachments,
creating an attachment against a memo, deleting an attachment, deleting a memo, importing an archive, and storage cleanup. Each would
have to rewrite the memo row, and the rebuild would have to start querying the attachment table. The single column
`attachment.memo_id` already answers the question exactly; a copy of it can only be equal or wrong.
**One field, `has_image`, defined by content alone.** Rejected. The most common way a photo reaches a memo is an upload that is never
referenced in the text, and a content-only flag would miss every one of those. Users asking for "memos with a picture" mean the
rendered memo, not the Markdown source.
**Name the stored flag `has_image`.** Rejected. It is published on the API as a content property and would be false on memos that
plainly show images. `has_inline_image` says what it measures and parallels `has_link` and `has_code`.
**Expose `has_inline_image` as a filter field too.** Deferred. Users think in "has image"; offering both invites the wrong pick. It
can be added later for "external images only" without any storage change.
**Keep the payload version in the `markdown` package.** Rejected. The version describes how memos are stored and upgraded, which the
Markdown engine does not know about. It sits with the rebuild in `core/memopayload`.
**Rebuild synchronously before serving.** Rejected. It is simple and race-free, but blocks startup for as long as the pass takes, which
on a large instance can exceed a container health check. The guarded write makes a background pass safe instead.
**Rebuild with the existing `UpdateMemo`.** Rejected. It writes the whole payload as read, so a user's tag or location change made
between the read and the write would be lost.
**Add an index on `attachment(memo_id)` now.** Deferred; see [Query cost](#query-cost).
## Future work
The `FieldKindExists` kind makes further relation-backed flags one schema entry each, with no storage change:
- `has_comments`: `memo_relation` rows with `related_memo_id = memo.id AND type = 'COMMENT'`, already served by
`idx_memo_relation_related_type_memo`. This needs an equality condition alongside the prefix one.
- `has_reactions`: `reaction.memo_id`.
- `has_video`, `has_audio`: the `has_image` subquery with a different MIME prefix and no content half.
`title`, which the payload already stores, is still not a filter field. A scalar JSON string field would allow `title.contains(...)`
and a `has_title` presence flag; it is a content fact and belongs in the payload where it already is.
+4
View File
@@ -11,6 +11,10 @@ extending or debugging the package.
- Define the backing column (`Column`), JSON path (if applicable), type, and
allowed operators.
- Include the CEL variable in `EnvOptions`.
- Choose the kind by where the truth lives: a payload flag
(`FieldKindJSONBool`) only for facts computed from the content; a fact about
related rows, such as attachments, uses `FieldKindExists` with `Related`,
never a payload copy.
2. **Adjust parser or renderer (if needed)**
- For non-scalar fields (JSON booleans, lists), add handling in
`parser.go` or extend the renderer helpers.
+7
View File
@@ -68,6 +68,13 @@ stmt, _ := engine.CompileToStatement(ctx, `has_task_list && visibility == "PUBLI
count as absent on every dialect; any other value — including an empty object —
counts as present. Only `==`/`!=` against a boolean literal (or bare/negated
use) is allowed.
- **Related-Row Flags** — `has_attachments` renders as `EXISTS` over
`attachment` rows whose `memo_id` is the memo. `has_image` ORs the payload
flag `property.hasInlineImage` (Markdown image syntax in the content) with an
`EXISTS` over attachments whose `type` starts with `image/`, ignoring case.
These facts are read at query time because attachment binding changes without
the content changing; never copy them into the payload. Comparisons follow the
presence flags.
- **String Matching** — `content.contains(x)`, `content.startsWith(x)`, and
`content.endsWith(x)` render as case-insensitive `LIKE`/`ILIKE` with LIKE
metacharacters (`%`, `_`, `\`) escaped. Available on scalar string fields whose
+122
View File
@@ -755,6 +755,128 @@ func TestJSONBoolComparisonSQLiteBehavior(t *testing.T) {
}
}
func TestRenderExistsComparisonsPerDialect(t *testing.T) {
t.Parallel()
engine, err := NewEngine(NewSchema())
require.NoError(t, err)
predicates := map[string]map[DialectName]string{
"has_attachments": {
DialectSQLite: "EXISTS (SELECT 1 FROM `attachment` WHERE `attachment`.`memo_id` = `memo`.`id`)",
DialectMySQL: "EXISTS (SELECT 1 FROM `attachment` WHERE `attachment`.`memo_id` = `memo`.`id`)",
DialectPostgres: "EXISTS (SELECT 1 FROM attachment WHERE attachment.memo_id = memo.id)",
},
"has_image": {
DialectSQLite: "(JSON_EXTRACT(`memo`.`payload`, '$.property.hasInlineImage') IS TRUE OR " +
"EXISTS (SELECT 1 FROM `attachment` WHERE `attachment`.`memo_id` = `memo`.`id` AND LOWER(`attachment`.`type`) LIKE 'image/%'))",
DialectMySQL: "(COALESCE(JSON_EXTRACT(`memo`.`payload`, '$.property.hasInlineImage'), CAST('false' AS JSON)) = CAST('true' AS JSON) OR " +
"EXISTS (SELECT 1 FROM `attachment` WHERE `attachment`.`memo_id` = `memo`.`id` AND LOWER(`attachment`.`type`) LIKE 'image/%'))",
DialectPostgres: "((memo.payload->'property'->>'hasInlineImage')::boolean IS TRUE OR " +
"EXISTS (SELECT 1 FROM attachment WHERE attachment.memo_id = memo.id AND LOWER(attachment.type) LIKE 'image/%'))",
},
}
for field, byDialect := range predicates {
for dialect, predicate := range byDialect {
cases := []struct {
expr string
sql string
}{
{field, predicate},
{"!" + field, "NOT (" + predicate + ")"},
{field + " == true", predicate},
{field + " == false", "NOT (" + predicate + ")"},
{field + " != true", "NOT (" + predicate + ")"},
{field + " != false", predicate},
}
for _, tc := range cases {
stmt, err := engine.CompileToStatement(context.Background(), tc.expr, RenderOptions{Dialect: dialect})
require.NoError(t, err, dialect, tc.expr)
require.Equal(t, tc.sql, stmt.SQL, dialect, tc.expr)
require.Empty(t, stmt.Args, dialect, tc.expr)
}
}
}
}
func TestRenderExistsRejectsUnsupportedOperators(t *testing.T) {
t.Parallel()
engine, err := NewEngine(NewSchema())
require.NoError(t, err)
for _, expr := range []string{`has_image > false`, `has_attachments == "yes"`, `"image" in has_image`} {
_, err := engine.CompileToStatement(context.Background(), expr, RenderOptions{Dialect: DialectSQLite})
require.Error(t, err, expr)
}
}
// TestExistsSQLiteBehavior pins has_attachments and has_image against real
// tables: has_attachments follows attachment.memo_id alone, and has_image is
// true for Markdown image syntax or an attached image/* file, whatever the
// MIME type's case, and false for other attachments and unbound uploads.
func TestExistsSQLiteBehavior(t *testing.T) {
db, err := sql.Open("sqlite", ":memory:")
require.NoError(t, err)
db.SetMaxOpenConns(1)
t.Cleanup(func() { require.NoError(t, db.Close()) })
_, err = db.Exec(`CREATE TABLE memo (id INTEGER PRIMARY KEY, payload TEXT)`)
require.NoError(t, err)
_, err = db.Exec(`CREATE TABLE attachment (id INTEGER PRIMARY KEY, memo_id INTEGER, type TEXT NOT NULL DEFAULT '')`)
require.NoError(t, err)
for _, fixture := range []struct {
id int
payload any
}{
{1, `{}`}, // nothing
{2, `{"property":{"hasInlineImage":true}}`}, // external image in content, no attachment
{3, `{}`}, // uploaded photo, not referenced in content
{4, `{}`}, // PDF attachment only
{5, `{"property":{"hasInlineImage":true}}`}, // managed inline image, also bound
{6, nil}, // NULL payload, upper-case MIME image
{7, `{"property":{"hasInlineImage":false}}`}, // explicit false flag, nothing attached
} {
_, err = db.Exec(`INSERT INTO memo (id, payload) VALUES (?, ?)`, fixture.id, fixture.payload)
require.NoError(t, err)
}
for _, attachment := range []struct {
memoID any
mimeType string
}{
{3, "image/jpeg"},
{4, "application/pdf"},
{5, "image/png"},
{6, "IMAGE/HEIC"},
{nil, "image/png"}, // uploaded but not bound to any memo
} {
_, err = db.Exec(`INSERT INTO attachment (memo_id, type) VALUES (?, ?)`, attachment.memoID, attachment.mimeType)
require.NoError(t, err)
}
engine, err := NewEngine(NewSchema())
require.NoError(t, err)
cases := []struct {
expr string
want []int
}{
{`has_attachments`, []int{3, 4, 5, 6}},
{`!has_attachments`, []int{1, 2, 7}},
{`has_attachments == false`, []int{1, 2, 7}},
{`has_image`, []int{2, 3, 5, 6}},
{`!has_image`, []int{1, 4, 7}},
{`has_image != true`, []int{1, 4, 7}},
{`has_attachments && !has_image`, []int{4}},
{`has_image && !has_attachments`, []int{2}},
}
for _, tc := range cases {
stmt, err := engine.CompileToStatement(context.Background(), tc.expr, RenderOptions{Dialect: DialectSQLite})
require.NoError(t, err, tc.expr)
require.Equal(t, tc.want, selectMemoIDs(t, db, stmt), tc.expr)
}
}
func TestCompileRejectsOversizedExpression(t *testing.T) {
t.Parallel()
engine, err := NewEngine(NewSchema())
+60
View File
@@ -196,6 +196,12 @@ func (r *renderer) renderFieldPredicate(cond *FieldPredicateCondition) (renderRe
return renderResult{}, errors.Wrap(err, "failed to render JSON existence predicate")
}
return renderResult{sql: sql}, nil
case FieldKindExists:
sql, err := r.existsPredicate(field)
if err != nil {
return renderResult{}, errors.Wrap(err, "failed to render existence predicate")
}
return renderResult{sql: sql}, nil
default:
return renderResult{}, errors.Errorf("field %q cannot be used as a predicate", cond.Field)
}
@@ -215,6 +221,8 @@ func (r *renderer) renderComparison(cond *ComparisonCondition) (renderResult, er
return r.renderJSONBoolComparison(field, cond.Operator, cond.Right)
case FieldKindJSONExists:
return r.renderJSONExistsComparison(field, cond.Operator, cond.Right)
case FieldKindExists:
return r.renderExistsComparison(field, cond.Operator, cond.Right)
case FieldKindScalar:
return r.renderScalarComparison(field, cond.Operator, cond.Right)
default:
@@ -773,6 +781,49 @@ func (r *renderer) renderJSONExistsComparison(field Field, op ComparisonOperator
return renderPredicateComparison(field, op, value, existsSQL)
}
// existsPredicate renders a FieldKindExists field: an EXISTS subquery over the
// related rows, OR-ed with the field's JSON boolean flag when it has one. The
// flag goes through jsonBoolPredicate, so a missing key or NULL payload reads
// as false and the whole expression stays two-valued under NOT.
func (r *renderer) existsPredicate(field Field) (string, error) {
related := field.Related
if related == nil {
return "", errors.Errorf("field %q has no related rows", field.Name)
}
where := fmt.Sprintf("%s = %s",
qualifyColumn(r.dialect, Column{Table: related.Table, Name: related.ForeignKey}),
qualifyColumn(r.dialect, related.Owner))
if related.PrefixColumn != "" {
if related.Prefix == "" || strings.ContainsAny(related.Prefix, `'"%_\`) {
return "", errors.Errorf("field %q has an unsafe prefix %q", field.Name, related.Prefix)
}
where += fmt.Sprintf(" AND LOWER(%s) LIKE '%s%%'",
qualifyColumn(r.dialect, Column{Table: related.Table, Name: related.PrefixColumn}),
strings.ToLower(related.Prefix))
}
exists := fmt.Sprintf("EXISTS (SELECT 1 FROM %s WHERE %s)", quoteTable(r.dialect, related.Table), where)
if len(field.JSONPath) == 0 {
return exists, nil
}
flag, err := r.jsonBoolPredicate(field)
if err != nil {
return "", err
}
return fmt.Sprintf("(%s OR %s)", flag, exists), nil
}
func (r *renderer) renderExistsComparison(field Field, op ComparisonOperator, right ValueExpr) (renderResult, error) {
value, err := expectBool(right)
if err != nil {
return renderResult{}, errors.Wrap(err, "existence comparison requires a boolean value")
}
predicate, err := r.existsPredicate(field)
if err != nil {
return renderResult{}, errors.Wrap(err, "failed to render existence comparison")
}
return renderPredicateComparison(field, op, value, predicate)
}
// renderPredicateComparison renders `field == value` or `field != value` for a
// field whose truth is fully described by predicate: the predicate itself when
// the comparison asks for true, its negation when it asks for false.
@@ -882,6 +933,15 @@ func sqlOperator(op ComparisonOperator) string {
return string(op)
}
func quoteTable(d DialectName, table string) string {
switch d {
case DialectPostgres:
return table
default:
return fmt.Sprintf("`%s`", table)
}
}
func qualifyColumn(d DialectName, col Column) string {
switch d {
case DialectPostgres:
+61
View File
@@ -37,6 +37,9 @@ const (
FieldKindJSONExists FieldKind = "json_exists"
FieldKindJSONList FieldKind = "json_list"
FieldKindVirtualAlias FieldKind = "virtual_alias"
// FieldKindExists represents a boolean derived from the presence of related
// rows in another table, optionally OR-ed with a JSON boolean flag.
FieldKindExists FieldKind = "exists"
)
// Column identifies the backing table column.
@@ -45,6 +48,22 @@ type Column struct {
Name string
}
// RelatedRows identifies the rows of another table that belong to a record,
// for fields of kind FieldKindExists.
type RelatedRows struct {
// Table is the related table.
Table string
// ForeignKey is the column of Table that holds the owner's key.
ForeignKey string
// Owner is the outer column ForeignKey refers to, such as memo.id.
Owner Column
// PrefixColumn and Prefix, when set, keep only related rows whose
// PrefixColumn starts with Prefix, ignoring case. Prefix is a schema
// constant and must not contain quotes or LIKE wildcards.
PrefixColumn string
Prefix string
}
// Field captures the schema metadata for an exposed CEL identifier.
type Field struct {
Name string
@@ -52,6 +71,7 @@ type Field struct {
Type FieldType
Column Column
JSONPath []string
Related *RelatedRows
AliasFor string
SupportsContains bool
Expressions map[DialectName]string
@@ -254,6 +274,45 @@ func NewSchema() Schema {
CompareNeq: true,
},
},
// Attachment binding lives in attachment.memo_id and changes without the
// memo content changing, so it is read at query time, never copied into
// the memo payload.
"has_attachments": {
Name: "has_attachments",
Kind: FieldKindExists,
Type: FieldTypeBool,
Related: &RelatedRows{
Table: "attachment",
ForeignKey: "memo_id",
Owner: Column{Table: "memo", Name: "id"},
},
AllowedComparisonOps: map[ComparisonOperator]bool{
CompareEq: true,
CompareNeq: true,
},
},
// has_image answers "does the memo show a picture": Markdown image syntax
// in the content (the stored hasInlineImage flag) or an attached image
// file that renders in the attachment strip. Both halves are needed; the
// stored flag alone misses photos that are uploaded but not referenced.
"has_image": {
Name: "has_image",
Kind: FieldKindExists,
Type: FieldTypeBool,
Column: Column{Table: "memo", Name: "payload"},
JSONPath: []string{"property", "hasInlineImage"},
Related: &RelatedRows{
Table: "attachment",
ForeignKey: "memo_id",
Owner: Column{Table: "memo", Name: "id"},
PrefixColumn: "type",
Prefix: "image/",
},
AllowedComparisonOps: map[ComparisonOperator]bool{
CompareEq: true,
CompareNeq: true,
},
},
}
envOptions := []cel.EnvOption{
@@ -273,6 +332,8 @@ func NewSchema() Schema {
cel.Variable("has_code", cel.BoolType),
cel.Variable("has_incomplete_tasks", cel.BoolType),
cel.Variable("has_location", cel.BoolType),
cel.Variable("has_attachments", cel.BoolType),
cel.Variable("has_image", cel.BoolType),
cel.Variable("now", cel.TimestampType),
ext.Sets(),
cel.ASTValidators(cel.ValidateRegexLiterals()),
+6
View File
@@ -251,6 +251,9 @@ func (s *service) ExtractProperties(content []byte) (*storepb.MemoPayload_Proper
case gast.KindCodeBlock, gast.KindFencedCodeBlock, gast.KindCodeSpan:
prop.HasCode = true
case gast.KindImage:
prop.HasInlineImage = true
case east.KindTaskCheckBox:
prop.HasTaskList = true
if checkBox, ok := n.(*east.TaskCheckBox); ok {
@@ -482,6 +485,9 @@ func (s *service) ExtractAll(content []byte) (*ExtractedData, error) {
case gast.KindCodeBlock, gast.KindFencedCodeBlock, gast.KindCodeSpan:
data.Property.HasCode = true
case gast.KindImage:
data.Property.HasInlineImage = true
case east.KindTaskCheckBox:
data.Property.HasTaskList = true
if checkBox, ok := n.(*east.TaskCheckBox); ok {
+33
View File
@@ -345,6 +345,39 @@ func TestExtractProperties(t *testing.T) {
}
}
// TestExtractInlineImage pins HasInlineImage to Markdown image syntax, managed
// or external, and keeps both property walks in agreement.
func TestExtractInlineImage(t *testing.T) {
tests := []struct {
name string
content string
want bool
}{
{name: "plain text", content: "No pictures here", want: false},
{name: "link is not an image", content: "[photo](https://example.com/a.png)", want: false},
{name: "external image", content: "![sunset](https://example.com/sunset.jpg)", want: true},
{name: "managed attachment image", content: "![](/file/attachments/abc123)", want: true},
{name: "reference-style image", content: "![logo][l]\n\n[l]: https://example.com/logo.svg", want: true},
{name: "image inside a link", content: "[![badge](https://example.com/b.svg)](https://example.com)", want: true},
{name: "image syntax in a code span", content: "`![x](https://example.com/x.png)`", want: false},
{name: "image syntax in a code block", content: "```\n![x](https://example.com/x.png)\n```", want: false},
{name: "raw HTML img", content: `<img src="https://example.com/x.png">`, want: false},
}
svc := NewService()
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
props, err := svc.ExtractProperties([]byte(tt.content))
require.NoError(t, err)
assert.Equal(t, tt.want, props.HasInlineImage, "ExtractProperties")
data, err := svc.ExtractAll([]byte(tt.content))
require.NoError(t, err)
assert.Equal(t, tt.want, data.Property.HasInlineImage, "ExtractAll")
})
}
}
func TestExtractAllTitle(t *testing.T) {
svc := NewService(WithTagExtension())
+7 -1
View File
@@ -299,6 +299,9 @@ message Memo {
// Whether the content contains an unchecked task.
bool has_incomplete_tasks = 5;
// Whether the content contains a Markdown image.
bool has_inline_image = 6;
}
}
@@ -321,7 +324,10 @@ message ListMemosRequest {
// supports == and comparisons against null, e.g. space != null),
// tags (list<string>; match with `"work" in tags`, not `tag == "work"`),
// has_task_list / has_link / has_code / has_incomplete_tasks (bool),
// has_location (bool; true when the memo has a location attached).
// has_location (bool; true when the memo has a location attached),
// has_attachments (bool; true when a file is attached to the memo),
// has_image (bool; true when the content contains a Markdown image or an
// image file is attached).
// Note: the time fields here are created_ts / updated_ts, which differ from
// the create_time / update_time names used by order_by.
// Examples:
+19 -6
View File
@@ -362,7 +362,10 @@ type ListMemosRequest struct {
// supports == and comparisons against null, e.g. space != null),
// tags (list<string>; match with `"work" in tags`, not `tag == "work"`),
// has_task_list / has_link / has_code / has_incomplete_tasks (bool),
// has_location (bool; true when the memo has a location attached).
// has_location (bool; true when the memo has a location attached),
// has_attachments (bool; true when a file is attached to the memo),
// has_image (bool; true when the content contains a Markdown image or an
// image file is attached).
//
// Note: the time fields here are created_ts / updated_ts, which differ from
// the create_time / update_time names used by order_by.
@@ -2252,8 +2255,10 @@ type Memo_Property struct {
HasTaskList bool `protobuf:"varint,4,opt,name=has_task_list,json=hasTaskList,proto3" json:"has_task_list,omitempty"`
// Whether the content contains an unchecked task.
HasIncompleteTasks bool `protobuf:"varint,5,opt,name=has_incomplete_tasks,json=hasIncompleteTasks,proto3" json:"has_incomplete_tasks,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
// Whether the content contains a Markdown image.
HasInlineImage bool `protobuf:"varint,6,opt,name=has_inline_image,json=hasInlineImage,proto3" json:"has_inline_image,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *Memo_Property) Reset() {
@@ -2321,6 +2326,13 @@ func (x *Memo_Property) GetHasIncompleteTasks() bool {
return false
}
func (x *Memo_Property) GetHasInlineImage() bool {
if x != nil {
return x.HasInlineImage
}
return false
}
// MemoRef identifies a memo in a relation.
type MemoRelation_MemoRef struct {
state protoimpl.MessageState `protogen:"open.v1"`
@@ -2382,7 +2394,7 @@ var File_api_memo_service_proto protoreflect.FileDescriptor
const file_api_memo_service_proto_rawDesc = "" +
"\n" +
"\x16api/memo_service.proto\x12\tmemos.api\x1a\x1capi/attachment_service.proto\x1a\x10api/common.proto\x1a\x1cgoogle/api/annotations.proto\x1a\x17google/api/client.proto\x1a\x1fgoogle/api/field_behavior.proto\x1a\x19google/api/resource.proto\x1a\x1bgoogle/protobuf/empty.proto\x1a google/protobuf/field_mask.proto\x1a\x1fgoogle/protobuf/timestamp.proto\"\xc4\b\n" +
"\x16api/memo_service.proto\x12\tmemos.api\x1a\x1capi/attachment_service.proto\x1a\x10api/common.proto\x1a\x1cgoogle/api/annotations.proto\x1a\x17google/api/client.proto\x1a\x1fgoogle/api/field_behavior.proto\x1a\x19google/api/resource.proto\x1a\x1bgoogle/protobuf/empty.proto\x1a google/protobuf/field_mask.proto\x1a\x1fgoogle/protobuf/timestamp.proto\"\xee\b\n" +
"\x04Memo\x12\x17\n" +
"\x04name\x18\x01 \x01(\tB\x03\xe0A\bR\x04name\x120\n" +
"\acreator\x18\x02 \x01(\tB\x16\xe0A\x03\xfaA\x10\n" +
@@ -2408,13 +2420,14 @@ const file_api_memo_service_proto_rawDesc = "" +
"\vcreate_time\x18\x10 \x01(\v2\x1a.google.protobuf.TimestampB\x03\xe0A\x01R\n" +
"createTime\x12@\n" +
"\vupdate_time\x18\x11 \x01(\v2\x1a.google.protobuf.TimestampB\x03\xe0A\x01R\n" +
"updateTime\x1a\xac\x01\n" +
"updateTime\x1a\xd6\x01\n" +
"\bProperty\x12\x14\n" +
"\x05title\x18\x01 \x01(\tR\x05title\x12\x19\n" +
"\bhas_link\x18\x02 \x01(\bR\ahasLink\x12\x19\n" +
"\bhas_code\x18\x03 \x01(\bR\ahasCode\x12\"\n" +
"\rhas_task_list\x18\x04 \x01(\bR\vhasTaskList\x120\n" +
"\x14has_incomplete_tasks\x18\x05 \x01(\bR\x12hasIncompleteTasks:.\xeaA+\n" +
"\x14has_incomplete_tasks\x18\x05 \x01(\bR\x12hasIncompleteTasks\x12(\n" +
"\x10has_inline_image\x18\x06 \x01(\bR\x0ehasInlineImage:.\xeaA+\n" +
"\x0ememos.api/Memo\x12\fmemos/{memo}*\x05memos2\x04memoB\b\n" +
"\x06_spaceB\v\n" +
"\t_locationB\t\n" +
+7 -1
View File
@@ -697,7 +697,10 @@ paths:
supports == and comparisons against null, e.g. space != null),
tags (list<string>; match with `"work" in tags`, not `tag == "work"`),
has_task_list / has_link / has_code / has_incomplete_tasks (bool),
has_location (bool; true when the memo has a location attached).
has_location (bool; true when the memo has a location attached),
has_attachments (bool; true when a file is attached to the memo),
has_image (bool; true when the content contains a Markdown image or an
image file is attached).
Note: the time fields here are created_ts / updated_ts, which differ from
the create_time / update_time names used by order_by.
Examples:
@@ -4733,6 +4736,9 @@ components:
hasIncompleteTasks:
type: boolean
description: Whether the content contains an unchecked task.
hasInlineImage:
type: boolean
description: Whether the content contains a Markdown image.
description: Property holds properties computed from the memo content.
MotionMedia:
type: object
+15 -4
View File
@@ -519,8 +519,11 @@ type InstanceBasicSetting struct {
SecretKey string `protobuf:"bytes,1,opt,name=secret_key,json=secretKey,proto3" json:"secret_key,omitempty"`
// The current schema version of database.
SchemaVersion string `protobuf:"bytes,2,opt,name=schema_version,json=schemaVersion,proto3" json:"schema_version,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
// The memopayload.Version every memo's content-derived payload has been
// rebuilt to. A lower value makes the server rebuild them in the background.
PayloadVersion int32 `protobuf:"varint,3,opt,name=payload_version,json=payloadVersion,proto3" json:"payload_version,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *InstanceBasicSetting) Reset() {
@@ -567,6 +570,13 @@ func (x *InstanceBasicSetting) GetSchemaVersion() string {
return ""
}
func (x *InstanceBasicSetting) GetPayloadVersion() int32 {
if x != nil {
return x.PayloadVersion
}
return 0
}
type InstanceGeneralSetting struct {
state protoimpl.MessageState `protogen:"open.v1"`
// disallow_user_registration disallows user registration.
@@ -1740,11 +1750,12 @@ const file_store_instance_setting_proto_rawDesc = "" +
"\x0eaccess_setting\x18\t \x01(\v2\".memos.store.InstanceAccessSettingH\x00R\raccessSetting\x12[\n" +
"\x14usage_limits_setting\x18\n" +
" \x01(\v2'.memos.store.InstanceUsageLimitsSettingH\x00R\x12usageLimitsSettingB\a\n" +
"\x05value\"\\\n" +
"\x05value\"\x85\x01\n" +
"\x14InstanceBasicSetting\x12\x1d\n" +
"\n" +
"secret_key\x18\x01 \x01(\tR\tsecretKey\x12%\n" +
"\x0eschema_version\x18\x02 \x01(\tR\rschemaVersion\"\xd6\x03\n" +
"\x0eschema_version\x18\x02 \x01(\tR\rschemaVersion\x12'\n" +
"\x0fpayload_version\x18\x03 \x01(\x05R\x0epayloadVersion\"\xd6\x03\n" +
"\x16InstanceGeneralSetting\x12<\n" +
"\x1adisallow_user_registration\x18\x01 \x01(\bR\x18disallowUserRegistration\x124\n" +
"\x16disallow_password_auth\x18\x02 \x01(\bR\x14disallowPasswordAuth\x12+\n" +
+16 -6
View File
@@ -89,9 +89,11 @@ type MemoPayload_Property struct {
HasCode bool `protobuf:"varint,3,opt,name=has_code,json=hasCode,proto3" json:"has_code,omitempty"`
HasIncompleteTasks bool `protobuf:"varint,4,opt,name=has_incomplete_tasks,json=hasIncompleteTasks,proto3" json:"has_incomplete_tasks,omitempty"`
// The title extracted from the first H1 heading, if present.
Title string `protobuf:"bytes,5,opt,name=title,proto3" json:"title,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
Title string `protobuf:"bytes,5,opt,name=title,proto3" json:"title,omitempty"`
// Whether the content contains a Markdown image.
HasInlineImage bool `protobuf:"varint,6,opt,name=has_inline_image,json=hasInlineImage,proto3" json:"has_inline_image,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *MemoPayload_Property) Reset() {
@@ -159,6 +161,13 @@ func (x *MemoPayload_Property) GetTitle() string {
return ""
}
func (x *MemoPayload_Property) GetHasInlineImage() bool {
if x != nil {
return x.HasInlineImage
}
return false
}
type MemoPayload_Location struct {
state protoimpl.MessageState `protogen:"open.v1"`
Placeholder string `protobuf:"bytes,1,opt,name=placeholder,proto3" json:"placeholder,omitempty"`
@@ -223,17 +232,18 @@ var File_store_memo_proto protoreflect.FileDescriptor
const file_store_memo_proto_rawDesc = "" +
"\n" +
"\x10store/memo.proto\x12\vmemos.store\"\xb6\x03\n" +
"\x10store/memo.proto\x12\vmemos.store\"\xe0\x03\n" +
"\vMemoPayload\x12=\n" +
"\bproperty\x18\x01 \x01(\v2!.memos.store.MemoPayload.PropertyR\bproperty\x12=\n" +
"\blocation\x18\x02 \x01(\v2!.memos.store.MemoPayload.LocationR\blocation\x12\x12\n" +
"\x04tags\x18\x03 \x03(\tR\x04tags\x1a\xac\x01\n" +
"\x04tags\x18\x03 \x03(\tR\x04tags\x1a\xd6\x01\n" +
"\bProperty\x12\x19\n" +
"\bhas_link\x18\x01 \x01(\bR\ahasLink\x12\"\n" +
"\rhas_task_list\x18\x02 \x01(\bR\vhasTaskList\x12\x19\n" +
"\bhas_code\x18\x03 \x01(\bR\ahasCode\x120\n" +
"\x14has_incomplete_tasks\x18\x04 \x01(\bR\x12hasIncompleteTasks\x12\x14\n" +
"\x05title\x18\x05 \x01(\tR\x05title\x1af\n" +
"\x05title\x18\x05 \x01(\tR\x05title\x12(\n" +
"\x10has_inline_image\x18\x06 \x01(\bR\x0ehasInlineImage\x1af\n" +
"\bLocation\x12 \n" +
"\vplaceholder\x18\x01 \x01(\tR\vplaceholder\x12\x1a\n" +
"\blatitude\x18\x02 \x01(\x01R\blatitude\x12\x1c\n" +
+3
View File
@@ -49,6 +49,9 @@ message InstanceBasicSetting {
string secret_key = 1;
// The current schema version of database.
string schema_version = 2;
// The memopayload.Version every memo's content-derived payload has been
// rebuilt to. A lower value makes the server rebuild them in the background.
int32 payload_version = 3;
}
message InstanceGeneralSetting {
+2
View File
@@ -19,6 +19,8 @@ message MemoPayload {
bool has_incomplete_tasks = 4;
// The title extracted from the first H1 heading, if present.
string title = 5;
// Whether the content contains a Markdown image.
bool has_inline_image = 6;
}
message Location {
+1
View File
@@ -367,6 +367,7 @@ func convertMemoPropertyFromStore(property *storepb.MemoPayload_Property) *apipb
HasTaskList: property.HasTaskList,
HasCode: property.HasCode,
HasIncompleteTasks: property.HasIncompleteTasks,
HasInlineImage: property.HasInlineImage,
Title: property.Title,
}
}
+28
View File
@@ -8,11 +8,13 @@ import (
"net/http"
"os"
"path"
"sync"
"time"
"uuid"
"github.com/pkg/errors"
"github.com/usememos/memos/core/memopayload"
"github.com/usememos/memos/internal/clientip"
"github.com/usememos/memos/internal/httphandler"
"github.com/usememos/memos/internal/profile"
@@ -47,6 +49,11 @@ type Server struct {
handler http.Handler
httpServer *http.Server
apiService *api.APIService
// backgroundCancel stops the startup jobs, and backgroundJobs waits for
// them, before the store closes.
backgroundCancel context.CancelFunc
backgroundJobs sync.WaitGroup
}
func NewServer(ctx context.Context, profile *profile.Profile, store *store.Store) (*Server, error) {
@@ -152,9 +159,29 @@ func (s *Server) Start() error {
}
}()
s.startBackgroundJobs()
return nil
}
// startBackgroundJobs runs one-off data jobs that must not delay serving.
func (s *Server) startBackgroundJobs() {
ctx, cancel := context.WithCancel(context.Background())
s.backgroundCancel = cancel
runner := memopayload.NewRunner(s.Store, s.apiService.MarkdownService)
s.backgroundJobs.Go(func() {
if err := runner.Backfill(ctx); err != nil && ctx.Err() == nil {
slog.Error("failed to rebuild memo payloads; retrying on next start", slog.String("error", err.Error()))
}
})
}
func (s *Server) stopBackgroundJobs() {
if s.backgroundCancel != nil {
s.backgroundCancel()
}
s.backgroundJobs.Wait()
}
func (s *Server) Shutdown(ctx context.Context) {
ctx, cancel := context.WithTimeout(ctx, shutdownTimeout)
defer cancel()
@@ -164,6 +191,7 @@ func (s *Server) Shutdown(ctx context.Context) {
s.closeLongLivedConnections()
s.shutdownHTTPServer(ctx)
s.apiService.CloseUploads()
s.stopBackgroundJobs()
// Close database connection.
if err := s.Store.Close(); err != nil {
+17
View File
@@ -354,3 +354,20 @@ func (d *DB) DeleteMemo(ctx context.Context, delete *store.DeleteMemo) error {
}
return nil
}
// RefreshMemoDerivedPayload sets the payload's tags and property while the
// content is unchanged; JSON_SET keeps every other payload key. The content
// comparison is binary so a case-insensitive collation cannot match an edit.
func (d *DB) RefreshMemoDerivedPayload(ctx context.Context, refresh *store.RefreshMemoDerivedPayload) error {
tags, property, err := refresh.JSON()
if err != nil {
return err
}
if _, err := d.db.ExecContext(ctx,
"UPDATE `memo` SET `payload` = JSON_SET(COALESCE(`payload`, JSON_OBJECT()), '$.tags', CAST(? AS JSON), '$.property', CAST(? AS JSON)) WHERE `id` = ? AND CAST(`content` AS BINARY) = CAST(? AS BINARY)",
tags, property, refresh.ID, refresh.Content,
); err != nil {
return errors.Wrap(err, "failed to refresh memo payload")
}
return nil
}
+16
View File
@@ -333,3 +333,19 @@ func (d *DB) DeleteMemo(ctx context.Context, delete *store.DeleteMemo) error {
}
return nil
}
// RefreshMemoDerivedPayload sets the payload's tags and property while the
// content is unchanged; jsonb_set keeps every other payload key.
func (d *DB) RefreshMemoDerivedPayload(ctx context.Context, refresh *store.RefreshMemoDerivedPayload) error {
tags, property, err := refresh.JSON()
if err != nil {
return err
}
if _, err := d.db.ExecContext(ctx,
"UPDATE memo SET payload = jsonb_set(jsonb_set(COALESCE(payload, '{}'::jsonb), '{tags}', "+placeholder(1)+"::jsonb), '{property}', "+placeholder(2)+"::jsonb) WHERE id = "+placeholder(3)+" AND content = "+placeholder(4),
tags, property, refresh.ID, refresh.Content,
); err != nil {
return errors.Wrap(err, "failed to refresh memo payload")
}
return nil
}
+16
View File
@@ -324,3 +324,19 @@ func (d *DB) DeleteMemo(ctx context.Context, delete *store.DeleteMemo) error {
}
return nil
}
// RefreshMemoDerivedPayload sets the payload's tags and property while the
// content is unchanged; JSON_SET keeps every other payload key.
func (d *DB) RefreshMemoDerivedPayload(ctx context.Context, refresh *store.RefreshMemoDerivedPayload) error {
tags, property, err := refresh.JSON()
if err != nil {
return err
}
if _, err := d.db.ExecContext(ctx,
"UPDATE `memo` SET `payload` = JSON_SET(COALESCE(NULLIF(`payload`, ''), '{}'), '$.tags', JSON(?), '$.property', JSON(?)) WHERE `id` = ? AND `content` = ?",
tags, property, refresh.ID, refresh.Content,
); err != nil {
return errors.Wrap(err, "failed to refresh memo payload")
}
return nil
}
+1
View File
@@ -32,6 +32,7 @@ type Driver interface {
CreateMemo(ctx context.Context, create *Memo) (*Memo, error)
ListMemos(ctx context.Context, find *FindMemo) ([]*Memo, error)
UpdateMemo(ctx context.Context, update *UpdateMemo) error
RefreshMemoDerivedPayload(ctx context.Context, refresh *RefreshMemoDerivedPayload) error
DeleteMemo(ctx context.Context, delete *DeleteMemo) error
DeleteMemoWithPolicy(ctx context.Context, delete *DeleteMemoWithPolicy) (*DeleteMemoWithPolicyResult, error)
// CountUserMemos counts the memos a user created, comments included, in every row status and Space.
+45 -2
View File
@@ -3,10 +3,12 @@ package store
import (
"context"
"database/sql"
"errors"
"encoding/json"
"github.com/pkg/errors"
"google.golang.org/protobuf/encoding/protojson"
"github.com/usememos/memos/internal/identifier"
storepb "github.com/usememos/memos/proto/gen/store"
)
@@ -105,6 +107,38 @@ type FindMemoPayload struct {
HasIncompleteTasks bool
}
// RefreshMemoDerivedPayload replaces the content-derived part of a memo's
// payload, its tags and property, computed from Content.
type RefreshMemoDerivedPayload struct {
ID int32
// Content is the memo content the tags and property were computed from.
// The refresh applies only while the stored content still equals it.
Content string
Tags []string
Property *storepb.MemoPayload_Property
}
// JSON returns the tags and property encoded the way memo payloads are stored.
func (r *RefreshMemoDerivedPayload) JSON() (tags string, property string, err error) {
tagList := r.Tags
if tagList == nil {
tagList = []string{}
}
tagBytes, err := json.Marshal(tagList)
if err != nil {
return "", "", errors.Wrap(err, "failed to marshal memo tags")
}
prop := r.Property
if prop == nil {
prop = &storepb.MemoPayload_Property{}
}
propertyBytes, err := protojson.Marshal(prop)
if err != nil {
return "", "", errors.Wrap(err, "failed to marshal memo property")
}
return string(tagBytes), string(propertyBytes), nil
}
type UpdateMemo struct {
ID int32
UID *string
@@ -267,6 +301,15 @@ func (s *Store) UpdateMemo(ctx context.Context, update *UpdateMemo) error {
return s.driver.UpdateMemo(ctx, update)
}
// RefreshMemoDerivedPayload rewrites a memo's payload tags and property in
// place, and only if the memo's content has not changed since it was read. It
// leaves every other payload field, such as the location, and updated_ts as
// they are, so a background rebuild can never undo a concurrent edit. A memo
// that was edited or deleted in the meantime is left alone.
func (s *Store) RefreshMemoDerivedPayload(ctx context.Context, refresh *RefreshMemoDerivedPayload) error {
return s.driver.RefreshMemoDerivedPayload(ctx, refresh)
}
func validateMemoWritePolicy(policy *MemoWritePolicy) error {
if policy == nil {
return nil
+83
View File
@@ -0,0 +1,83 @@
package test
import (
"context"
"testing"
"github.com/stretchr/testify/require"
storepb "github.com/usememos/memos/proto/gen/store"
"github.com/usememos/memos/store"
)
// TestRefreshMemoDerivedPayload pins the guarded rebuild write: it replaces
// tags and property only while the content is unchanged, and keeps the
// location and updated_ts, so a background rebuild cannot undo an edit.
func TestRefreshMemoDerivedPayload(t *testing.T) {
t.Parallel()
ctx := context.Background()
ts := NewTestingStore(ctx, t)
user, err := createTestingHostUser(ctx, ts)
require.NoError(t, err)
location := &storepb.MemoPayload_Location{Placeholder: "Harbour", Latitude: 1.5, Longitude: 2.5}
memo, err := ts.CreateMemo(ctx, &store.Memo{
UID: "payload-refresh",
CreatorID: user.ID,
Content: "Ünïcode ![sunset](https://example.com/s.jpg) #trip",
Visibility: store.Private,
// Fixed past timestamps, so a refresh that touched updated_ts within
// the same second as the fixture could not go unnoticed.
CreatedTs: 1700000000,
UpdatedTs: 1700000100,
Payload: &storepb.MemoPayload{
Tags: []string{"stale"},
Property: &storepb.MemoPayload_Property{HasCode: true},
Location: location,
},
})
require.NoError(t, err)
t.Run("matching content refreshes tags and property only", func(t *testing.T) {
require.NoError(t, ts.RefreshMemoDerivedPayload(ctx, &store.RefreshMemoDerivedPayload{
ID: memo.ID,
Content: memo.Content,
Tags: []string{"trip"},
Property: &storepb.MemoPayload_Property{HasInlineImage: true},
}))
got, err := ts.GetMemo(ctx, &store.FindMemo{ID: &memo.ID})
require.NoError(t, err)
require.Equal(t, []string{"trip"}, got.Payload.Tags)
require.True(t, got.Payload.Property.HasInlineImage)
require.False(t, got.Payload.Property.HasCode)
require.Equal(t, location.Placeholder, got.Payload.Location.GetPlaceholder())
require.InDelta(t, location.Latitude, got.Payload.Location.GetLatitude(), 1e-9)
require.Equal(t, int64(1700000100), got.UpdatedTs)
images, err := ts.ListMemos(ctx, &store.FindMemo{IDList: []int32{memo.ID}, Filters: []string{"has_image"}})
require.NoError(t, err)
require.Len(t, images, 1, "the refreshed flag must be visible to the filter")
})
t.Run("edited content is left alone", func(t *testing.T) {
require.NoError(t, ts.RefreshMemoDerivedPayload(ctx, &store.RefreshMemoDerivedPayload{
ID: memo.ID,
Content: "ünïcode ![sunset](https://example.com/s.jpg) #trip",
Tags: []string{"wrong"},
Property: &storepb.MemoPayload_Property{HasLink: true},
}))
got, err := ts.GetMemo(ctx, &store.FindMemo{ID: &memo.ID})
require.NoError(t, err)
require.Equal(t, []string{"trip"}, got.Payload.Tags, "a case-only difference must not match")
require.False(t, got.Payload.Property.HasLink)
})
t.Run("empty tags and property clear the stored values", func(t *testing.T) {
require.NoError(t, ts.RefreshMemoDerivedPayload(ctx, &store.RefreshMemoDerivedPayload{ID: memo.ID, Content: memo.Content}))
got, err := ts.GetMemo(ctx, &store.FindMemo{ID: &memo.ID})
require.NoError(t, err)
require.Empty(t, got.Payload.Tags)
require.False(t, got.Payload.GetProperty().GetHasInlineImage())
require.Equal(t, location.Placeholder, got.Payload.Location.GetPlaceholder())
})
}
+10
View File
@@ -7,9 +7,11 @@ import {
CodeIcon,
EyeIcon,
HashIcon,
ImageIcon,
LinkIcon,
type LucideIcon,
MapPinIcon,
PaperclipIcon,
SearchIcon,
XIcon,
} from "lucide-react";
@@ -79,6 +81,14 @@ const FILTER_CONFIGS: Record<FilterFactor, FilterConfig> = {
icon: MapPinIcon,
getLabel: (_, t) => t("memo.filters.has-location"),
},
"property.hasAttachments": {
icon: PaperclipIcon,
getLabel: (_, t) => t("memo.filters.has-attachments"),
},
"property.hasImage": {
icon: ImageIcon,
getLabel: (_, t) => t("memo.filters.has-image"),
},
};
interface FilterChipProps {
+3 -1
View File
@@ -12,7 +12,9 @@ export type FilterFactor =
| "property.hasLink"
| "property.hasTaskList"
| "property.hasCode"
| "property.hasLocation";
| "property.hasLocation"
| "property.hasAttachments"
| "property.hasImage";
export interface MemoFilter {
factor: FilterFactor;
+4
View File
@@ -68,6 +68,10 @@ export const buildMemoFilter = ({
conditions.push(`has_code`);
} else if (filter.factor === "property.hasLocation") {
conditions.push(`has_location`);
} else if (filter.factor === "property.hasAttachments") {
conditions.push(`has_attachments`);
} else if (filter.factor === "property.hasImage") {
conditions.push(`has_image`);
} else if (filter.factor === "displayTime") {
const range = getLocalDayTimestampRange(filter.value);
if (range) {
+2
View File
@@ -283,7 +283,9 @@
"delete-confirm-description": "هذا الإجراء لا رجعة فيه. ستتم إزالة المرفقات والروابط والمراجع أيضًا.",
"direction": "الاتجاه",
"filters": {
"has-attachments": "يحتوي على مرفقات",
"has-code": "يحتوي على كود",
"has-image": "يحتوي على صورة",
"has-link": "يحتوي على رابط",
"has-location": "يحتوي على موقع",
"has-task-list": "يحتوي على قائمة مهام"
+2
View File
@@ -392,7 +392,9 @@
"delete-confirm-description": "Bu əməliyyat geri qaytarıla bilməz. Qoşmalar, keçidlər və istinadlar da çıxarılacaq.",
"direction": "İstiqamət",
"filters": {
"has-attachments": "Qoşma var",
"has-code": "Kod var",
"has-image": "Şəkil var",
"has-link": "Keçid var",
"has-location": "Məkan var",
"has-task-list": "Tapşırıq siyahısı var"
+2
View File
@@ -327,7 +327,9 @@
"delete-confirm-description": "Това действие е необратимо. Прикачените файлове, връзките и препратките също ще бъдат премахнати.",
"direction": "Посока",
"filters": {
"has-attachments": "има прикачени файлове",
"has-code": "hasCode",
"has-image": "има изображение",
"has-link": "hasLink",
"has-location": "има местоположение",
"has-task-list": "hasTaskList"
+2
View File
@@ -288,7 +288,9 @@
"delete-confirm-description": "Aquesta acció és irreversible. Els adjunts, enllaços i referències també s'eliminaran.",
"direction": "Direcció",
"filters": {
"has-attachments": "té adjunts",
"has-code": "téCodi",
"has-image": "té imatge",
"has-link": "téEnllaç",
"has-location": "té ubicació",
"has-task-list": "téLlistaTasques"
+2
View File
@@ -288,7 +288,9 @@
"delete-confirm-description": "Tato akce je nevratná. Přílohy, odkazy a reference budou také odstraněny.",
"direction": "Směr",
"filters": {
"has-attachments": "má přílohy",
"has-code": "maKod",
"has-image": "má obrázek",
"has-link": "maOdkaz",
"has-location": "má polohu",
"has-task-list": "maSeznamUkolu"
+2
View File
@@ -327,7 +327,9 @@
"delete-confirm-description": "Denne handling er irreversibel. Vedhæftede filer, links og referencer vil også blive fjernet.",
"direction": "Retning",
"filters": {
"has-attachments": "har vedhæftninger",
"has-code": "hasCode",
"has-image": "har billede",
"has-link": "harLink",
"has-location": "har placering",
"has-task-list": "har Opgaveliste"
+2
View File
@@ -288,7 +288,9 @@
"delete-confirm-description": "Dieser Vorgang ist nicht rückgängig zu machen. Anhänge, Links und Verknüpfungen werden ebenfalls gelöscht.",
"direction": "Richtung",
"filters": {
"has-attachments": "hat Anhänge",
"has-code": "hatCode",
"has-image": "hat Bild",
"has-link": "hatLink",
"has-location": "hat Standort",
"has-task-list": "hatAufgabenliste"
+2
View File
@@ -327,7 +327,9 @@
"delete-confirm-description": "Αυτή η ενέργεια είναι μη αναστρέψιμη. Τα συνημμένα, οι σύνδεσμοι και οι αναφορές θα αφαιρεθούν επίσης.",
"direction": "Κατεύθυνση",
"filters": {
"has-attachments": "έχει συνημμένα",
"has-code": "έχει Κώδικα",
"has-image": "έχει εικόνα",
"has-link": "έχει Σύνδεσμο",
"has-location": "έχει τοποθεσία",
"has-task-list": "hasTaskList"
+2
View File
@@ -288,7 +288,9 @@
"delete-confirm-description": "This action is irreversible. Attachments, links, and references will also be removed.",
"direction": "Direction",
"filters": {
"has-attachments": "hasAttachments",
"has-code": "hasCode",
"has-image": "hasImage",
"has-link": "hasLink",
"has-location": "hasLocation",
"has-task-list": "hasTaskList"
+2
View File
@@ -392,7 +392,9 @@
"delete-confirm-description": "This action is irreversible. Attachments, links, and references will also be removed.",
"direction": "Direction",
"filters": {
"has-attachments": "hasAttachments",
"has-code": "hasCode",
"has-image": "hasImage",
"has-link": "hasLink",
"has-location": "hasLocation",
"has-task-list": "hasTaskList"
+2
View File
@@ -288,7 +288,9 @@
"delete-confirm-description": "Esta acción es irreversible. Los adjuntos, enlaces y referencias también se eliminarán.",
"direction": "Dirección",
"filters": {
"has-attachments": "tiene adjuntos",
"has-code": "tieneCódigo",
"has-image": "tiene imagen",
"has-link": "tieneEnlace",
"has-location": "tiene ubicación",
"has-task-list": "tieneListaTareas"
+2
View File
@@ -327,7 +327,9 @@
"delete-confirm-description": "See toiming on pöördumatu. Samuti eemaldatakse manused, lingid ja viited.",
"direction": "Suund",
"filters": {
"has-attachments": "on manuseid",
"has-code": "hasCode",
"has-image": "on pilt",
"has-link": "hasLink",
"has-location": "on asukoht",
"has-task-list": "hasTaskList"
+2
View File
@@ -283,7 +283,9 @@
"delete-confirm-description": "این عمل غیرقابل بازگشت است. پیوست‌ها، پیوندها و ارجاعات نیز حذف خواهند شد.",
"direction": "جهت",
"filters": {
"has-attachments": "دارای پیوست",
"has-code": "دارای کد",
"has-image": "دارای تصویر",
"has-link": "دارای پیوند",
"has-location": "دارای موقعیت",
"has-task-list": "دارای لیست کارها"
+2
View File
@@ -327,7 +327,9 @@
"delete-confirm-description": "Tämä toimenpide on peruuttamaton. Myös liitteet, linkit ja viittaukset poistetaan.",
"direction": "Suunta",
"filters": {
"has-attachments": "on liitteitä",
"has-code": "hasCode",
"has-image": "on kuva",
"has-link": "hasLink",
"has-location": "on sijainti",
"has-task-list": "hasTaskList"
+2
View File
@@ -288,7 +288,9 @@
"delete-confirm-description": "Cette action est irréversible. Les pièces jointes, liens et références seront également supprimés.",
"direction": "Direction",
"filters": {
"has-attachments": "a des pièces jointes",
"has-code": "aCode",
"has-image": "a une image",
"has-link": "aLien",
"has-location": "a une localisation",
"has-task-list": "aListeTâches"
+2
View File
@@ -288,7 +288,9 @@
"delete-confirm-description": "Esta acción non se pode desfacer. Vanse eliminar tamén as ligazóns e referencias.",
"direction": "Dirección",
"filters": {
"has-attachments": "ten anexos",
"has-code": "hasCode",
"has-image": "ten imaxe",
"has-link": "hasLink",
"has-location": "ten localización",
"has-task-list": "hasTaskList"
+2
View File
@@ -360,7 +360,9 @@
"delete-confirm-description": "פעולה זו אינה הפיכה. גם קבצים מצורפים, קישורים והפניות יוסרו.",
"direction": "כיוון",
"filters": {
"has-attachments": "מכיל קבצים מצורפים",
"has-code": "מכיל קוד",
"has-image": "מכיל תמונה",
"has-link": "מכיל קישור",
"has-location": "מכיל מיקום",
"has-task-list": "מכיל רשימת משימות"
+2
View File
@@ -283,7 +283,9 @@
"delete-confirm-description": "यह कार्रवाई वापस नहीं की जा सकती। संलग्नक, लिंक और संदर्भ भी हटा दिए जाएंगे।",
"direction": "दिशा",
"filters": {
"has-attachments": "अटैचमेंट है",
"has-code": "कोड है",
"has-image": "छवि है",
"has-link": "लिंक है",
"has-location": "स्थान है",
"has-task-list": "टास्क लिस्ट है"
+2
View File
@@ -288,7 +288,9 @@
"delete-confirm-description": "Ova akcija je nepovratna. Privici, linkovi i reference će također biti uklonjeni.",
"direction": "Smjer",
"filters": {
"has-attachments": "ima privitke",
"has-code": "imaKod",
"has-image": "ima sliku",
"has-link": "imaLink",
"has-location": "ima lokaciju",
"has-task-list": "imaZadatke"
+2
View File
@@ -288,7 +288,9 @@
"delete-confirm-description": "Ez a művelet visszafordíthatatlan. A mellékletek, hivatkozások és referenciák is törlődnek.",
"direction": "Irány",
"filters": {
"has-attachments": "van melléklet",
"has-code": "vanKód",
"has-image": "van kép",
"has-link": "vanLink",
"has-location": "van helyadat",
"has-task-list": "vanFeladatLista"
+2
View File
@@ -283,7 +283,9 @@
"delete-confirm-description": "Tindakan ini tidak dapat dibatalkan. Lampiran, tautan, dan referensi juga akan dihapus.",
"direction": "Arah",
"filters": {
"has-attachments": "Memiliki lampiran",
"has-code": "Memiliki kode",
"has-image": "Memiliki gambar",
"has-link": "Memiliki tautan",
"has-location": "Memiliki lokasi",
"has-task-list": "Memiliki daftar tugas"
+2
View File
@@ -288,7 +288,9 @@
"delete-confirm-description": "Questa azione è irreversibile. Allegati, link e riferimenti saranno rimossi.",
"direction": "Direzione",
"filters": {
"has-attachments": "ha allegati",
"has-code": "haCodice",
"has-image": "ha un'immagine",
"has-link": "haLink",
"has-location": "ha una posizione",
"has-task-list": "haListaCompiti"
+2
View File
@@ -288,7 +288,9 @@
"delete-confirm-description": "この操作は元に戻せません。添付ファイル、リンク、参照も削除されます。",
"direction": "並び順",
"filters": {
"has-attachments": "添付ファイルあり",
"has-code": "コードあり",
"has-image": "画像あり",
"has-link": "リンクあり",
"has-location": "位置情報あり",
"has-task-list": "タスクリストあり"
+2
View File
@@ -288,7 +288,9 @@
"delete-confirm-description": "ეს ქმედება შეუქცევადია. დანართები, ლინკები და რეფერენციებიც წაიშლება.",
"direction": "მიმართულება",
"filters": {
"has-attachments": "აქვს დანართები",
"has-code": "კოდიარის",
"has-image": "აქვს სურათი",
"has-link": "ლინკიარის",
"has-location": "აქვს მდებარეობა",
"has-task-list": "სიისამოცანებია"
+2
View File
@@ -283,7 +283,9 @@
"delete-confirm-description": "이 행동은 되돌릴 수 없으며, 첨부파일, 링크 및 참조가 삭제됩니다.",
"direction": "정렬",
"filters": {
"has-attachments": "첨부 파일 있음",
"has-code": "코드있음",
"has-image": "이미지 있음",
"has-link": "링크있음",
"has-location": "위치 있음",
"has-task-list": "할일목록있음"
+2
View File
@@ -327,7 +327,9 @@
"delete-confirm-description": "Šis veiksmas yra negrįžtamas. Taip pat bus pašalinti priedai, nuorodos ir nuorodos.",
"direction": "Kryptis",
"filters": {
"has-attachments": "turi priedų",
"has-code": "hasCode",
"has-image": "turi paveikslėlį",
"has-link": "hasLink",
"has-location": "turi vietą",
"has-task-list": "turiTaskList"
+2
View File
@@ -327,7 +327,9 @@
"delete-confirm-description": "Šī darbība ir neatgriezeniska. Tiks noņemti arī pielikumi, saites un atsauces.",
"direction": "Virziens",
"filters": {
"has-attachments": "ir pielikumi",
"has-code": "hasCode",
"has-image": "ir attēls",
"has-link": "hasLink",
"has-location": "ir atrašanās vieta",
"has-task-list": "hasTaskList"
+2
View File
@@ -283,7 +283,9 @@
"delete-confirm-description": "ही क्रिया अपरिवर्तनीय आहे. संलग्नक, लिंक आणि संदर्भ देखील काढून टाकले जातील.",
"direction": "दिशा",
"filters": {
"has-attachments": "संलग्नक आहे",
"has-code": "कोड आहे",
"has-image": "प्रतिमा आहे",
"has-link": "लिंक आहे",
"has-location": "स्थान आहे",
"has-task-list": "कार्यसूची आहे"
+2
View File
@@ -288,7 +288,9 @@
"delete-confirm-description": "Denne handlingen kan ikke angres. Vedlegg, lenker og referanser vil også bli fjernet.",
"direction": "Retning",
"filters": {
"has-attachments": "har vedlegg",
"has-code": "harKode",
"has-image": "har bilde",
"has-link": "harLink",
"has-location": "har posisjon",
"has-task-list": "harGjøremålsListe"
+2
View File
@@ -288,7 +288,9 @@
"delete-confirm-description": "Deze actie is onomkeerelijk. Bijlagen, links en referenties worden ook verwijderd.",
"direction": "Richting",
"filters": {
"has-attachments": "heeft bijlagen",
"has-code": "heeftCode",
"has-image": "heeft afbeelding",
"has-link": "heeftLink",
"has-location": "heeft locatie",
"has-task-list": "heeftTakenlijst"
+2
View File
@@ -388,7 +388,9 @@
"delete-confirm-description": "Denne handlinga kan ikkje gjerast om. Vedlegg, lenkjer og tilvisingar vert òg fjerna.",
"direction": "Retning",
"filters": {
"has-attachments": "Har vedlegg",
"has-code": "Har kode",
"has-image": "Har bilete",
"has-link": "Har lenkje",
"has-location": "Har stad",
"has-task-list": "Har gjeremålsliste"
+2
View File
@@ -288,7 +288,9 @@
"delete-confirm-description": "Czy na pewno chcesz usunąć tę notatkę? Załączniki, linki i odnośniki także będą usunięte. TA AKCJA JEST NIEODWRACALNA",
"direction": "Kierunek",
"filters": {
"has-attachments": "ma załączniki",
"has-code": "ma kod",
"has-image": "ma obraz",
"has-link": "ma link",
"has-location": "ma lokalizację",
"has-task-list": "ma listę zadań"
+2
View File
@@ -283,7 +283,9 @@
"delete-confirm-description": "Esta ação é irreversível. Anexos, links e referências também serão removidos.",
"direction": "Sentido",
"filters": {
"has-attachments": "tem anexos",
"has-code": "temCódigo",
"has-image": "tem imagem",
"has-link": "temLink",
"has-location": "tem localização",
"has-task-list": "temListaDeTarefas"
+2
View File
@@ -288,7 +288,9 @@
"delete-confirm-description": "Esta ação é irreversível. Os anexos, links e referências também serão removidos.",
"direction": "Direção",
"filters": {
"has-attachments": "tem anexos",
"has-code": "temCódigo",
"has-image": "tem imagem",
"has-link": "temLink",
"has-location": "tem localização",
"has-task-list": "temListaDeTarefas"
+2
View File
@@ -327,7 +327,9 @@
"delete-confirm-description": "Această acțiune este ireversibilă. Atașamentele, linkurile și referințele vor fi, de asemenea, eliminate.",
"direction": "Direcţie",
"filters": {
"has-attachments": "are atașamente",
"has-code": "areCode",
"has-image": "are imagine",
"has-link": "areLink",
"has-location": "are locație",
"has-task-list": "areTaskList"
+2
View File
@@ -288,7 +288,9 @@
"delete-confirm-description": "Это действие нельзя отменить. Вложения, ссылки и упоминания также будут удалены.",
"direction": "Сортировка",
"filters": {
"has-attachments": "есть вложения",
"has-code": "hasCode",
"has-image": "есть изображение",
"has-link": "hasLink",
"has-location": "есть местоположение",
"has-task-list": "hasTaskList"
+2
View File
@@ -327,7 +327,9 @@
"delete-confirm-description": "Táto akcia je nezvratná. Odstránia sa aj prílohy, odkazy a referencie.",
"direction": "Smer",
"filters": {
"has-attachments": "má prílohy",
"has-code": "hasCode",
"has-image": "má obrázok",
"has-link": "hasLink",
"has-location": "má polohu",
"has-task-list": "hasTaskList"
+2
View File
@@ -288,7 +288,9 @@
"delete-confirm-description": "To dejanje je nepovratno. Priložene datoteke, povezave in reference bodo prav tako odstranjene.",
"direction": "Smer",
"filters": {
"has-attachments": "ima priloge",
"has-code": "imaKodo",
"has-image": "ima sliko",
"has-link": "imaPovezavo",
"has-location": "imaLokacijo",
"has-task-list": "imaSeznamOpravil"
+2
View File
@@ -327,7 +327,9 @@
"delete-confirm-description": "Ова акција је неповратна. Прилози, везе и референце ће такође бити уклоњени.",
"direction": "Правац",
"filters": {
"has-attachments": "има прилоге",
"has-code": "хасЦоде",
"has-image": "има слику",
"has-link": "хасЛинк",
"has-location": "има локацију",
"has-task-list": "хасТаскЛист"
+2
View File
@@ -288,7 +288,9 @@
"delete-confirm-description": "Denna åtgärd är oåterkallelig. Bilagor, länk och referenser kommer också att tas bort.",
"direction": "Riktning",
"filters": {
"has-attachments": "har bilagor",
"has-code": "harKod",
"has-image": "har bild",
"has-link": "harLänk",
"has-location": "har plats",
"has-task-list": "harAttGöraLista"
+2
View File
@@ -283,7 +283,9 @@
"delete-confirm-description": "การดำเนินการนี้ไม่สามารถย้อนกลับได้ ไฟล์แนบ ลิงก์ และการอ้างอิงจะถูกลบออกด้วย",
"direction": "ทิศทาง",
"filters": {
"has-attachments": "มีไฟล์แนบ",
"has-code": "มีโค้ด",
"has-image": "มีรูปภาพ",
"has-link": "มีลิงก์",
"has-location": "มีตำแหน่ง",
"has-task-list": "มีรายการที่ต้องทำ"
+2
View File
@@ -320,7 +320,9 @@
"delete-confirm-description": "Bu işlem geri alınamaz. Ekler, bağlantılar ve referanslar da kaldırılacaktır.",
"direction": "Yön",
"filters": {
"has-attachments": "Ek içerir",
"has-code": "Kod içerir",
"has-image": "Görsel içerir",
"has-link": "Bağlantı içerir",
"has-location": "Konum içerir",
"has-task-list": "Yapılacaklar listesi içerir"
+2
View File
@@ -288,7 +288,9 @@
"delete-confirm-description": "Ця дія є незворотною. Вкладення, посилання та посилання також буде видалено.",
"direction": "Напрямок",
"filters": {
"has-attachments": "є вкладення",
"has-code": "єКод",
"has-image": "є зображення",
"has-link": "єПосилання",
"has-location": "є розташування",
"has-task-list": "єСписокЗавдань"
+2
View File
@@ -283,7 +283,9 @@
"delete-confirm-description": "Hành động này không thể hoàn tác. Tệp đính kèm, liên kết và tham chiếu cũng sẽ bị xóa.",
"direction": "Hướng",
"filters": {
"has-attachments": "có tệp đính kèm",
"has-code": "cóMã",
"has-image": "có hình ảnh",
"has-link": "cóLiênKết",
"has-location": "có vị trí",
"has-task-list": "cóDanhSáchViệc"
+2
View File
@@ -315,7 +315,9 @@
"delete-confirm-description": "此操作是不可逆的,附件、链接和引用也会被删除。",
"direction": "排序方式",
"filters": {
"has-attachments": "有附件",
"has-code": "有代码",
"has-image": "有图片",
"has-link": "有链接",
"has-location": "有位置",
"has-task-list": "有待办"
+2
View File
@@ -368,7 +368,9 @@
"delete-confirm-description": "此操作無法恢復。附件、連結和引用將一併被移除。",
"direction": "排序",
"filters": {
"has-attachments": "有附件",
"has-code": "有程式碼",
"has-image": "有圖片",
"has-link": "有連結",
"has-location": "有位置",
"has-task-list": "有待辦事項"
+16
View File
@@ -8,8 +8,10 @@ import {
Clock3Icon,
ExternalLinkIcon,
FilterIcon,
ImageIcon,
MapPinIcon,
MoreVerticalIcon,
PaperclipIcon,
ParenthesesIcon,
PencilIcon,
PinIcon,
@@ -111,6 +113,18 @@ const memoViewExamples = [
description: "Memos without an attached location.",
icon: MapPinIcon,
},
{
title: "With attachments",
filter: "has_attachments",
description: "Memos with at least one attached file.",
icon: PaperclipIcon,
},
{
title: "Photos",
filter: "has_image",
description: "Memos that show an image, in the content or as an attached file.",
icon: ImageIcon,
},
{
title: "Content search",
filter: 'content.contains("TODO")',
@@ -197,6 +211,8 @@ const filterFields = [
"has_link",
"has_code",
"has_location",
"has_attachments",
"has_image",
'created_ts >= now - duration("24h")',
"created_ts.getFullYear() == ...",
"created_ts.getMonth() == ... (0 = Jan)",
File diff suppressed because one or more lines are too long
+3 -1
View File
@@ -89,10 +89,12 @@ describe("memo views", () => {
{ factor: "property.hasTaskList", value: "" },
{ factor: "property.hasCode", value: "" },
{ factor: "property.hasLocation", value: "" },
{ factor: "property.hasAttachments", value: "" },
{ factor: "property.hasImage", value: "" },
],
includePinned: false,
}),
).toBe("(has_link) && (has_task_list) && (has_code) && (has_location)");
).toBe("(has_link) && (has_task_list) && (has_code) && (has_location) && (has_attachments) && (has_image)");
});
it("uses a saved memo view filter", () => {