fasttier_layers.py

clew/fasttier_layers.py

The per-file text layers the fast tier recomputes for an edited file.

refresh_code_text

bool clew.fasttier_layers.refresh_code_text(sqlite3.Connection conn, Path repo_root, str rel, IndexCache cache, str old_sha, list old_rows)

Replace one file's rows in the contentless code corpus.

clew/fasttier_layers.py:210

Show on the map →

Called by _apply

Calls _has, _refresh_file_scope, code_text_rows, file_code_texts, spans_key

Source · 50 lines
def refresh_code_text(
    conn: sqlite3.Connection,
    repo_root: Path,
    rel: str,
    cache: IndexCache,
    old_sha: str,
    old_rows: list,
) -> bool:
    """A CONTENTLESS FTS5 TABLE DELETES ONLY BY RESTATING WHAT WAS INDEXED: the `'delete'` command
    needs each row's exact old text, and SQLite 3.37 has no contentless-delete. That text is in
    the cache — the full stage memoized it under the OLD content sha and the OLD spans — so it is
    read back, never recomputed from the new bytes. Not there, nothing is touched and the caller
    keeps the corpus on the stale list.

    v2 (1.3.10): and the file's row in the file-scope corpus.

    @brief Delete the old corpus rows, insert the new.
    @return Whether the corpus is current for this file.
    """
    from .code_text import (
        CODE_TEXT_STAGE_VERSION,
        TABLE,
        code_text_rows,
        file_code_texts,
        spans_key,
    )

    if not _has(conn, TABLE):
        return True
    old = (
        cache.extract_get(old_sha, "code_text", CODE_TEXT_STAGE_VERSION, spans_key(old_rows))
        if old_rows
        else {"v": []}
    )
    if old is None:
        return False
    for row, text in zip(old_rows, old["v"] or [], strict=False):
        conn.execute(
            f"INSERT INTO {TABLE} ({TABLE}, rowid, body) VALUES ('delete', ?, ?)",
            (int(row[0]), text),
        )
    new_rows = code_text_rows(conn, rel)
    texts = file_code_texts(cache, repo_root, rel, new_rows) if new_rows else []
    conn.executemany(
        f"INSERT INTO {TABLE} (rowid, body) VALUES (?, ?)",
        [(int(r[0]), t) for r, t in zip(new_rows, texts or [], strict=False)],
    )
    return _refresh_file_scope(conn, repo_root, rel, cache, old_sha, old_rows, new_rows)

Activity · 12 steps
lines 229–235from .code_text import ( CODE_TEXT_STAGE_VERSION, TABLE, code_text_rows, file_code_texts, spans_key, )lines 237–237◇ if not _has(conn, TABLE)lines 238–238return Truelines 239–243old = ( cache.extract_get(old_sha, "code_text", CODE_TEXT_STAGE_VERSION, spans_key(old_rows)) if old_rows else {"v": []} )lines 244–244◇ if old is Nonelines 245–245return Falselines 246–246◇ for row, text in zip(old_rows, old["v"] or [], strict=False)lines 247–250conn.execute( f"INSERT INTO {TABLE} ({TABLE}, rowid, body) VALUES ('delete', ?, ?)", (int(row[0]), text), )lines 251–251new_rows = code_text_rows(conn, rel)lines 252–252texts = file_code_texts(cache, repo_root, rel, new_rows) if new_rows else []lines 253–256conn.executemany( f"INSERT INTO {TABLE} (rowid, body) VALUES (?, ?)", [(int(r[0]), t) for r, t in zip(new_rows, texts or [], strict=False)], )lines 257–257return _refresh_file_scope(conn, repo_root, rel, cache, old_sha, old_rows, new_rows)

Requirements

REQ-DDB-INDEX-006

refresh_text_layers

None clew.fasttier_layers.refresh_text_layers(sqlite3.Connection conn, Path repo_root, str rel, IndexCache cache)

Rewrite every per-file text layer for one edited file.

clew/fasttier_layers.py:32

Show on the map →

Called by _apply

Calls _refresh_file_doc, _refresh_generated, _refresh_mentions, refresh_file_license, refresh_kerneldoc

Source · 14 lines
def refresh_text_layers(
    conn: sqlite3.Connection, repo_root: Path, rel: str, cache: IndexCache
) -> None:
    """@brief Recompute file docs, mentions, generated-file evidence, licence and kernel-doc. @return None."""
    from .kerneldoc import refresh_kerneldoc
    from .licenses import refresh_file_license

    _refresh_file_doc(conn, repo_root, rel, cache)
    _refresh_mentions(conn, repo_root, rel, cache)
    _refresh_generated(conn, repo_root, rel, cache)
    refresh_file_license(conn, repo_root, rel, cache)
    refresh_kerneldoc(conn, repo_root, rel, cache)

Activity · 7 steps
lines 36–36from .kerneldoc import refresh_kerneldoclines 37–37from .licenses import refresh_file_licenselines 39–39_refresh_file_doc(conn, repo_root, rel, cache)lines 40–40_refresh_mentions(conn, repo_root, rel, cache)lines 41–41_refresh_generated(conn, repo_root, rel, cache)lines 42–42refresh_file_license(conn, repo_root, rel, cache)lines 43–43refresh_kerneldoc(conn, repo_root, rel, cache)

Requirements

REQ-DDB-INDEX-006