Commit Graph

58 Commits

Author SHA1 Message Date
William Casarin afc42d1952 nostrdb/writer: make sure we don't write a note if we already have it
I'm noticing duplicate notes in the database, which might happen when
the ingester and writer get spammed with the same note rapidly. Add a
sanity check during the write so that we only ever write a note once.

Fixes: 1cf898e0b2 ("ndb: update nostrdb")
Changelog-Fixed: Fix duplicate notes getting written to nostrdb
Signed-off-by: William Casarin <jb55@jb55.com>
2023-12-04 14:54:28 -08:00
William Casarin 6b8cf51720 nostrdb/search: fix another newest-first bug
Signed-off-by: William Casarin <jb55@jb55.com>
2023-12-02 15:04:23 -08:00
William Casarin 65be56ba7c fix some incompatibility between nostrdb and damus' 2023-12-02 13:44:03 -08:00
William Casarin 8e361a9586 nostrdb/search: fix subtle bug with some newest-first text search
Due to the way the range queries work for newest-first searches, we can
have a situation where the MDB_SET_RANGE gets placed on either the
correct place or just after the correct place. To position the cursor
correctly, we jump back one if the search result prefix doesn't match.

Signed-off-by: William Casarin <jb55@jb55.com>
2023-12-02 13:44:03 -08:00
William Casarin 9bbeffe320 nostrdb/search: also index longform
Signed-off-by: William Casarin <jb55@jb55.com>
2023-12-02 13:44:03 -08:00
William Casarin 3e5d7581ba nostrdb/refactor: move search key printer in case we need it
Signed-off-by: William Casarin <jb55@jb55.com>
2023-12-02 13:44:03 -08:00
William Casarin 06445de197 nostrdb/search: make sure we break instead of return
so the cursor has a chance to close

Signed-off-by: William Casarin <jb55@jb55.com>
2023-12-02 13:44:03 -08:00
William Casarin e537c7cef4 nostrdb/search: allow searching from newest-to-oldest and oldest-to-newest
Signed-off-by: William Casarin <jb55@jb55.com>
2023-12-02 13:44:03 -08:00
William Casarin 01c239c0eb nostrdb/search: add limit param
If we only care to have a certain number of results

Signed-off-by: William Casarin <jb55@jb55.com>
2023-12-02 13:44:03 -08:00
William Casarin bec92249f9 nostrdb/search: remove result printing, move to util/ndb
Signed-off-by: William Casarin <jb55@jb55.com>
2023-12-02 13:44:03 -08:00
hakkadaikon aa0b9bde8f nostrdb/Delete unuse argument (destsize)
Closes: https://github.com/damus-io/nostrdb/pull/18
Reviewed-by: William Casarin <jb55@jb55.com>
Signed-off-by: William Casarin <jb55@jb55.com>
2023-12-02 13:44:03 -08:00
William Casarin 4e4e8ed460 nostrdb/rename get_physical_cores to get_cpu_cores
less wrong

Signed-off-by: William Casarin <jb55@jb55.com>
2023-12-02 13:44:03 -08:00
William Casarin 3605edad8b nostrdb/config: fix ingester thread settings
Signed-off-by: William Casarin <jb55@jb55.com>
2023-12-02 13:44:03 -08:00
William Casarin 04c207a11a nostrdb/ingest: add configurable ingest filter
This allows users of nostrdb to selectively filter notes of any kind during
ingest.

Contact lists too big? Create a filter to reject them.

You only care about notes with specific kinds? Reject everything else.

Damus will use this for rejecting large events that might take up too
much space for storage, such as contact lists.

This commit also switched to ndb_config for configuring nostrdb, because
the arguments to ndb_init were getting out of hand.

Changelog-Added: Added ingest filter setting
Changelog-Changed: Switch to ndb_config for per-session ndb settings
Signed-off-by: William Casarin <jb55@jb55.com>
2023-12-02 13:44:03 -08:00
William Casarin 9d208284c6 nostrdb/search: phrase searching working
This changes the search algorithm to be much smarter and more efficient
at searching phrases.

It is also much simpler, using less intermediate data structures.

Signed-off-by: William Casarin <jb55@jb55.com>
2023-12-02 13:44:03 -08:00
William Casarin 213a26cd01 nostrdb/flag: add ndb config flag for skipping note verification
makes some large imports a bit faster

Signed-off-by: William Casarin <jb55@jb55.com>
2023-12-02 13:44:03 -08:00
William Casarin b74bde5cc4 nostrdb/search: fix infinite loop when parsing some notes
Our word parser gets stuck on some notes with utf8 chars. Make sure we
are always advancing so we don't get stuck.

Signed-off-by: William Casarin <jb55@jb55.com>
2023-12-02 13:44:03 -08:00
William Casarin 0e0c53145f nostrdb/segfault: fix weird crash in ispunct
Signed-off-by: William Casarin <jb55@jb55.com>
2023-12-02 13:44:03 -08:00
William Casarin 76aa1d3450 nostrdb/db: remove the DUPFIXED flag from the fulltext db
I don't think this technically makes any sense

Signed-off-by: William Casarin <jb55@jb55.com>
2023-12-02 13:44:03 -08:00
William Casarin fa0d5e7d03 nostrdb/debug: fix some debug-mode compile issues
Signed-off-by: William Casarin <jb55@jb55.com>
2023-12-02 13:44:03 -08:00
William Casarin 8446db7cbc nostrdb/search: prepare text search for accurate phrase results
This patch sets the stage for phrase searching. It collects data into
result sets based on words and the word's associated key. We can use
this data to select the best search results based on adjacent
word_indices.

Signed-off-by: William Casarin <jb55@jb55.com>
2023-12-02 13:44:03 -08:00
William Casarin 8679c9f293 nostrdb/search: make search case insensitive
Signed-off-by: William Casarin <jb55@jb55.com>
2023-12-02 13:44:03 -08:00
William Casarin d541153e4c nostrdb/Add fulltext search index
Signed-off-by: William Casarin <jb55@jb55.com>
2023-12-02 13:44:03 -08:00
William Casarin 53fc1b6945 nostrdb/Fix invalid db selection when writing kind index
Fixes: ebe92071af18 ("index: write kind index when processing notes")
Signed-off-by: William Casarin <jb55@jb55.com>
2023-12-02 13:44:03 -08:00
William Casarin ff60f8a2db nostrdb/index: write kind index when processing notes
We have a kind index database now, so write to it when processing notes

Signed-off-by: William Casarin <jb55@jb55.com>
2023-12-02 13:44:03 -08:00
William Casarin bfd78c01ca nostrdb/refactor: move write id index to its own function
We will be writing more indices so I'm trying to clean this up a bit
before this function gets too messy

Signed-off-by: William Casarin <jb55@jb55.com>
2023-12-02 13:44:03 -08:00
William Casarin a2af030367 nostrdb/refactor: move profile index writing to its own function
Signed-off-by: William Casarin <jb55@jb55.com>
2023-12-02 13:44:03 -08:00
William Casarin 3c2e8b728f nostrdb/index: create kind+timestamp index database
We don't build the index yet, but create the database like the others.

Signed-off-by: William Casarin <jb55@jb55.com>
2023-12-02 13:44:03 -08:00
William Casarin 8269ca59cd nostrdb/index: add u64_timestamp lmdb comparator
custom kind+timestamp comparison function. This is used by lmdb to
perform b+ tree searches over the kind+timestamp index.

Signed-off-by: William Casarin <jb55@jb55.com>
2023-12-02 13:44:03 -08:00
William Casarin 0f9d55d4f9 nostrdb/debug: use mdb_strerror in more places
instead of codes

Signed-off-by: William Casarin <jb55@jb55.com>
2023-12-02 13:44:03 -08:00
William Casarin 4109649dc2 nostrdb/filter: make sure we only match single chars
Without this, we could accidently match `pr` for `#p` filters

Fixes: 30ed801285dd ("filters: add initial filter interface")
Signed-off-by: William Casarin <jb55@jb55.com>
2023-12-02 13:44:03 -08:00
William Casarin 466dfcb7d7 nostrdb/filters: add initial filter interface
This adds a way to construct filters and match them against notes. This
will be used by our query interface in the future.

Signed-off-by: William Casarin <jb55@jb55.com>
2023-12-02 13:44:03 -08:00
William Casarin bc330ab5de update nostrdb
to include potential ingester thread crash fix
2023-11-14 10:26:09 -08:00
William Casarin 29fa4ecf2e build: fix invalid function name 2023-11-13 10:31:28 -08:00
William Casarin 518fdffce9 ndb: potential fix for a crash in some nostrdb queries 2023-11-13 10:31:28 -08:00
William Casarin cc385d3c3f nostrdb: add migration to fix local japanese profile names 2023-11-02 14:17:17 +09:00
William Casarin 1cf898e0b2 ndb: update nostrdb
This includes the new profile fetched_at logic and reaction stats.

When receiving new profiles, nostrdb will record when it was last
received in a new database. This database is a mapping from Pubkey to
timestamp.

You can manually read/write to this table using:

ndb_read_last_profile_fetch
ndb_write_last_profile_fetch

This patch also includes the new reaction counting metadata table. It is
not used yet (but reactions are still counted!)

Changelog-Added: Added reaction counters to nostrdb
Changelog-Added: Record when profile is last fetched in nostrdb
2023-10-23 10:40:11 +08:00
William Casarin b1c7ef9bd9 Fix profiles not updating
Timestamped IDs were not being initialized properly when writing profile
indices. This means that every profile was indexed with timestamp 0.
derp. Fix this!

Changelog-Fixed: Fix profiles not updating
2023-10-06 10:42:17 -07:00
William Casarin d0daa9fafa nostrdb: add last fetched records for profiles 2023-10-06 10:42:17 -07:00
William Casarin dacade299d ndb: bump nostrdb to support client->relay note processing 2023-09-24 17:06:04 -07:00
William Casarin 6f67c159ff ndb: switch to case-insensitive profile searches 2023-09-21 18:03:22 -04:00
William Casarin 7a85ae29ca search: switch to nostrdb profile searching
Changelog-Changed: Switch to nostrdb for @'s and user search
2023-09-21 13:19:22 -04:00
William Casarin fafe3b4b3e ndb: add nostrdb migrations 2023-09-21 09:10:06 -04:00
William Casarin fc9b9f2940 ndb: switch profile queries to use transactions
this should ensure no crashing occurs when querying profiles
2023-09-21 09:10:06 -04:00
William Casarin 9398877415 nostrdb/c: update to include transaction support 2023-09-21 09:10:06 -04:00
William Casarin 5657512370 ndb: restore escaped slash fix 2023-08-28 10:09:49 -07:00
William Casarin 882f6e2534 ndb: update nostrdb, fix alignment issues 2023-08-28 08:19:03 -07:00
William Casarin caffa0398b nostrdb: profile flatbuffers in nostrdb working! 2023-08-26 20:46:42 -07:00
William Casarin 1f5f1e28a4 nostrdb: pull latest, adding flatcc and lmdb 2023-08-25 19:05:34 -07:00
Daniel D‘Aquino 066b3cdde8 Fix image links appearing with escaped slashes
Changelog-Fixed: Fix images and links occasionally appearing with escaped slashes
Closes: https://github.com/damus-io/damus/issues/1468
Signed-off-by: Daniel D‘Aquino <daniel@daquino.me>
Signed-off-by: William Casarin <jb55@jb55.com>
Rewarded-sats: 50000
2023-08-18 08:41:21 -07:00