Skip to content

Commit e54fab4

Browse files
committed
Clean: preliminary thoughts superseded by the cache.
1 parent 01f1f37 commit e54fab4

1 file changed

Lines changed: 0 additions & 219 deletions

File tree

server/src/processing.rs

Lines changed: 0 additions & 219 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,6 @@
2020
// -------
2121
//
2222
// ### Standard library
23-
//
24-
// For commented-out caching code.
25-
/**
26-
use std::collections::{HashMap, HashSet};
27-
use std::fs::Metadata;
28-
use std::io;
29-
use std::ops::Deref;
30-
use std::rc::{Rc, Weak};
31-
*/
3223
use std::{
3324
borrow::Cow,
3425
cell::RefCell,
@@ -1629,216 +1620,6 @@ pub fn diff_code_mirror_doc_blocks(
16291620
change_specs
16301621
}
16311622

1632-
// Goal: make it easy to update the data structure. We update on every
1633-
// load/save, then do some accesses during those processes.
1634-
//
1635-
// Top-level data structures: a file HashSet\<PathBuf, FileAnchor> and an id
1636-
// HashMap\<id, {Anchor, HashSet\<referring\_id>}>. Some FileAnchors in the file
1637-
// HashSet are also in a pending load list..
1638-
//
1639-
// * To update a file:
1640-
// * Remove the old file from the file HasHMap. Add an empty FileAnchor to the
1641-
// file HashMap.
1642-
// * For each id, see if that id already exists.
1643-
// * If the id exists: if it refers to an id in the old FileAnchor, replace
1644-
// it with the new one. If not, need to perform resolution on this id (we
1645-
// have a non-unique id; how to fix?).
1646-
// * If the id doesn't exist: create a new one.
1647-
// * For each hyperlink, see if that id already exists.
1648-
// * If so, upsert the referring id. Check the metadata on the id to make
1649-
// sure that data is current. If not, add this to the pending hyperlinks
1650-
// list. If the file is missing, delete it from the cache.
1651-
// * If not, create a new entry in the id HashSet and add the referring id
1652-
// to the HashSet. Add the file to a pending hyperlinks list.
1653-
// * When the file is processed:
1654-
// * Look for all entries in the pending file list that refer to the current
1655-
// file and resolve these. Start another task to load in all pending
1656-
// files.
1657-
// * Look at the old file; remove each id that's still in the id HashMap. If
1658-
// the id was in the HashMap and it also was a Hyperlink, remove that from
1659-
// the HashSet.
1660-
// * To remove a file from the HashMap:
1661-
// * Remove it from the file HashMap.
1662-
// * For each hyperlink, remove it from the HashSet of referring links (if
1663-
// that id still exists).
1664-
// * For each id, remove it from the id HashMap.
1665-
// * To add a file from the HashSet:
1666-
// * Perform an update with an empty FileAnchor.
1667-
//
1668-
// Pending hyperlinks list: for each hyperlink,
1669-
//
1670-
// * check if the id is now current in the cache. If so, add the referring id to
1671-
// the HashSet then move to the next hyperlink.
1672-
// * check if the file is now current in the cache. If not, load the file and
1673-
// update the cache, then go to step 1.
1674-
// * The id was not found, even in the expected file. Add the hyperlink to a
1675-
// broken links set?
1676-
//
1677-
// Global operations:
1678-
//
1679-
// * Scan all files, then perform add/upsert/removes based on differences with
1680-
// the cache.
1681-
//
1682-
// Functions:
1683-
//
1684-
// * Upsert an Anchor.
1685-
// * Upsert a Hyperlink.
1686-
// * Upsert a file.
1687-
// * Remove a file.
1688-
/*x
1689-
/// There are two types of files that can serve as an anchor: these are file
1690-
/// anchor targets.
1691-
enum FileAnchor {
1692-
Plain(PlainFileAnchor),
1693-
Html(HtmlFileAnchor),
1694-
}
1695-
1696-
/// This is the cached metadata for a file that serves as an anchor: perhaps an
1697-
/// image, a PDF, or a video.
1698-
struct PlainFileAnchor {
1699-
/// A relative path to this file, rooted at the project's TOC.
1700-
path: Rc<PathBuf>,
1701-
/// The globally-unique anchor used to link to this file. It's generated
1702-
/// based on hash of the file's contents, so that each file will have a
1703-
/// unique identifier.
1704-
anchor: String,
1705-
/// Metadata captured when this data was cached. If it disagrees with the
1706-
/// file's current state, then this cached data should be re=generated from
1707-
/// the file.
1708-
file_metadata: Metadata,
1709-
}
1710-
1711-
/// Cached metadata for an HTML file.
1712-
struct HtmlFileAnchor {
1713-
/// The file containing this HTML.
1714-
file_anchor: PlainFileAnchor,
1715-
/// The TOC numbering of this file.
1716-
numbering: Vec<Option<u32>>,
1717-
/// The headings in this file.
1718-
headings: Vec<HeadingAnchor>,
1719-
/// Anchors which appear before the first heading.
1720-
pre_anchors: Vec<NonHeadingAnchor>,
1721-
}
1722-
1723-
/// Cached metadata shared by both headings (which are also anchors) and
1724-
/// non-heading anchors.
1725-
struct AnchorCommon {
1726-
/// The HTML file containing this anchor.
1727-
html_file_anchor: Weak<FileAnchor>,
1728-
/// The globally-unique anchor used to link to this object.
1729-
anchor: String,
1730-
/// The inner HTML of this anchor.
1731-
inner_html: String,
1732-
/// The hyperlink this anchor contains.
1733-
hyperlink: Option<Rc<Hyperlink>>,
1734-
}
1735-
1736-
/// An anchor is defined only in these two places: the anchor source.
1737-
enum HtmlAnchor {
1738-
Heading(HeadingAnchor),
1739-
NonHeading(NonHeadingAnchor),
1740-
}
1741-
1742-
/// Cached metadata for a heading (which is always also an anchor).
1743-
struct HeadingAnchor {
1744-
anchor_common: AnchorCommon,
1745-
/// The numbering of this heading on the HTML file containing it.
1746-
numbering: Vec<Option<u32>>,
1747-
/// Non-heading anchors which appear after this heading but before the next
1748-
/// heading.
1749-
non_heading_anchors: Vec<NonHeadingAnchor>,
1750-
}
1751-
1752-
/// Cached metadata for a non-heading anchor.
1753-
struct NonHeadingAnchor {
1754-
anchor_common: AnchorCommon,
1755-
/// The heading this anchor appears after (unless it appears before the
1756-
/// first heading in this file).
1757-
parent_heading: Option<Weak<HeadingAnchor>>,
1758-
/// A snippet of HTML preceding this anchor.
1759-
pre_snippet: String,
1760-
/// A snippet of HTML following this anchor.
1761-
post_snippet: String,
1762-
/// If this is a numbered item, the name of the numbering group it belongs
1763-
/// to.
1764-
numbering_group: Option<String>,
1765-
/// If this is a numbered item, its number.
1766-
number: u32,
1767-
}
1768-
1769-
/// An anchor can refer to any of these structs: these are all possible anchor
1770-
/// targets.
1771-
enum Anchor {
1772-
Html(HtmlAnchor),
1773-
File(FileAnchor),
1774-
}
1775-
1776-
/// The metadata for a hyperlink.
1777-
struct Hyperlink {
1778-
/// The file this hyperlink refers to.
1779-
file: PathBuf,
1780-
/// The anchor this hyperlink refers to.
1781-
html_anchor: String,
1782-
}
1783-
1784-
/// The value stored in the id HashMap.
1785-
struct AnchorVal {
1786-
/// The target anchor this id refers to.
1787-
anchor: Anchor,
1788-
/// All hyperlinks which target this anchor.
1789-
referring_links: Rc<HashSet<String>>,
1790-
}
1791-
1792-
// Given HTML, catalog all link targets and link-like items, ensuring that they
1793-
// have a globally unique id.
1794-
fn html_analyze(
1795-
file_path: &Path,
1796-
html: &str,
1797-
mut file_map: HashMap<Rc<PathBuf>, Rc<FileAnchor>>,
1798-
mut anchor_map: HashMap<Rc<String>, HashSet<AnchorVal>>,
1799-
) -> io::Result<String> {
1800-
// Create the missing anchors:
1801-
//
1802-
// A missing file.
1803-
let missing_html_file_anchor = Rc::new(FileAnchor::Html(HtmlFileAnchor {
1804-
file_anchor: PlainFileAnchor {
1805-
path: Rc::new(PathBuf::new()),
1806-
anchor: "".to_string(),
1807-
// TODO: is there some way to create generic/empty metadata?
1808-
file_metadata: Path::new(".").metadata().unwrap(),
1809-
},
1810-
numbering: Vec::new(),
1811-
headings: Vec::new(),
1812-
pre_anchors: Vec::new(),
1813-
}));
1814-
// Define an anchor in this file.
1815-
let missing_anchor = NonHeadingAnchor {
1816-
anchor_common: AnchorCommon {
1817-
html_file_anchor: Rc::downgrade(&missing_html_file_anchor),
1818-
anchor: "".to_string(),
1819-
hyperlink: None,
1820-
inner_html: "".to_string(),
1821-
},
1822-
parent_heading: None,
1823-
pre_snippet: "".to_string(),
1824-
post_snippet: "".to_string(),
1825-
numbering_group: None,
1826-
number: 0,
1827-
};
1828-
// Add this to the top-level hashes.
1829-
let anchor_val = AnchorVal {
1830-
anchor: Anchor::Html(HtmlAnchor::NonHeading(missing_anchor)),
1831-
referring_links: Rc::new(HashSet::new()),
1832-
};
1833-
//file_map.insert(mfa.file_anchor.path, missing_html_file_anchor);
1834-
//let anchor_val_set: HashSet<AnchorVal> = HashSet::new();
1835-
//anchor_val_set.insert(anchor_val);
1836-
//anchor_map.insert(&mfa.file_anchor.anchor, anchor_val_set);
1837-
1838-
Ok("".to_string())
1839-
}
1840-
*/
1841-
18421623
// Tests
18431624
// -----
18441625
#[cfg(test)]

0 commit comments

Comments
 (0)