Fixes from the first round of TEST.md

SEO: a domain property (sc-domain:) covers every subdomain, so the shop,
Gitea and forum were counted as the website. What ranks, the morning
check, the Monday report, keywords, change candidates and the audit's
traffic now read only the website's own host (with or without www).
The report keeps pages worth a proposal apart from "Waiting for your
yes", explains only moves past the thresholds, and says "places up/down".

Also:
- Feed summaries drop the posts' scripts and styles.
- Spend you log can't be negative.
- Test and check buttons can't be clicked twice while they run.
- Previews show the site's web fonts and icon sprites.
- Backups are read without leaving -wal/-shm files; deleting one removes
  them, and leftovers are swept at start.
- The Overview's setup flags a CRM that Hermes can't reach.
- Import now says what came in; adding a prospect that exists says so;
  prospects can be deleted.
- Signal tags and brief addresses keep accented letters (Ü → u).
- Page errors start with a capital; clearer messages for bad uploads,
  CRM retry and cancel, keywords, and the finished audit.
- The module you're in stays unfolded in the sidebar.
- A picked keyword can be unpicked.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-24 06:31:42 -07:00
co-authored by Claude Opus 5.5
parent 3ddf716e71
commit c36f786ae9
52 changed files with 796 additions and 128 deletions
+76
View File
@@ -998,3 +998,79 @@ func Search(d *db.DB, words []string, limit int) ([]Company, []Contact, error) {
contacts, err := scanContacts(rows)
return companies, contacts, err
}
// Delete forgets a company (with its people) or a person added by mistake:
// their steps in the funnel and Hunter.io searches go too, and a CRM action
// that hasn't been done yet is taken back. A record Hermes already added to
// EspoCRM stays there.
func Delete(d *db.DB, kind string, id int64) error {
tbl, err := table(kind)
if err != nil {
return err
}
tx, err := d.Begin()
if err != nil {
return err
}
defer tx.Rollback()
var exists int
if err := tx.QueryRow(`SELECT count(*) FROM `+tbl+` WHERE id = ?`, id).Scan(&exists); err != nil {
return err
}
if exists == 0 {
return ErrNotFound
}
contacts := []int64{}
if kind == "contact" {
contacts = append(contacts, id)
} else {
rows, err := tx.Query(`SELECT id FROM prospect_contacts WHERE company_id = ?`, id)
if err != nil {
return err
}
for rows.Next() {
var c int64
if err := rows.Scan(&c); err != nil {
rows.Close()
return err
}
contacts = append(contacts, c)
}
rows.Close()
}
subjects := []any{}
if kind == "company" {
subjects = append(subjects, "company:"+strconv.FormatInt(id, 10))
}
for _, c := range contacts {
subjects = append(subjects, "contact:"+strconv.FormatInt(c, 10))
}
origins := make([]any, len(subjects))
for i, s := range subjects {
origins[i] = "prospect-" + s.(string)
}
in := "(?" + strings.Repeat(", ?", len(subjects)-1) + ")"
for _, q := range []struct {
sql string
args []any
}{
{`DELETE FROM funnel_events WHERE subject IN ` + in, subjects},
{`DELETE FROM enrich_runs WHERE subject IN ` + in, subjects},
{`UPDATE crm_actions SET status = 'cancelled' WHERE status IN ('pending', 'failed') AND origin IN ` + in, origins},
} {
if _, err := tx.Exec(q.sql, q.args...); err != nil {
return err
}
}
for _, c := range contacts {
if _, err := tx.Exec(`DELETE FROM prospect_contacts WHERE id = ?`, c); err != nil {
return err
}
}
if kind == "company" {
if _, err := tx.Exec(`DELETE FROM prospect_companies WHERE id = ?`, id); err != nil {
return err
}
}
return tx.Commit()
}
+38
View File
@@ -248,3 +248,41 @@ func TestAddWithoutEmails(t *testing.T) {
t.Error("a namesake without a company was merged")
}
}
func TestDelete(t *testing.T) {
d := openDB(t)
now := time.Now()
co, _, err := AddCompany(d, Company{Name: "Oops", Website: "https://oops.example", Source: SourceManual}, now)
if err != nil {
t.Fatal(err)
}
p1, _, _ := AddContact(d, Contact{CompanyID: co, FirstName: "Ann", LastName: "Oops", Email: "ann@oops.example", Source: SourceManual}, now)
p2, _, _ := AddContact(d, Contact{CompanyID: co, FirstName: "Solo", Email: "solo@oops.example", Source: SourceManual}, now)
if _, err := AcceptContact(d, p2, now); err != nil {
t.Fatal(err)
}
d.Exec(`INSERT INTO funnel_events (stage, channel, subject, source, at) VALUES ('paid', 'email', ?, 'manual', ?)`, "contact:"+strconv.FormatInt(p1, 10), now.Format(time.RFC3339))
if err := Delete(d, "contact", p1); err != nil {
t.Fatal(err)
}
var n int
d.QueryRow(`SELECT count(*) FROM funnel_events WHERE subject = ?`, "contact:"+strconv.FormatInt(p1, 10)).Scan(&n)
if n != 0 {
t.Errorf("funnel events left: %d", n)
}
if err := Delete(d, "company", co); err != nil {
t.Fatal(err)
}
d.QueryRow(`SELECT (SELECT count(*) FROM prospect_companies) + (SELECT count(*) FROM prospect_contacts)`).Scan(&n)
if n != 0 {
t.Errorf("prospects left: %d", n)
}
var status string
d.QueryRow(`SELECT status FROM crm_actions WHERE origin = ?`, "prospect-contact:"+strconv.FormatInt(p2, 10)).Scan(&status)
if status != "cancelled" {
t.Errorf("the queued Lead is %q", status)
}
if err := Delete(d, "company", co); !errors.Is(err, ErrNotFound) {
t.Errorf("deleting again: %v", err)
}
}