Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modlog: Support logging to a SQLite database #7513

Merged
merged 38 commits into from Oct 30, 2020

Conversation

AnnikaCodes
Copy link
Collaborator

This PR takes the next step in migrating modlogs to SQLite: starting dual logging to a SQLite database as well as text files.

I am currently implemented note ID search simply by streaming to regex in JavaScript; this seemed like the least bad option based on the discussions I've had.

Annika added 2 commits October 12, 2020 16:33
This PR takes the next step in migrating modlogs to SQLite: starting dual logging to a SQLite database as well as text files.

I am currently implemented note ID search simply by streaming to regex in JavaScript; this seemed like the least bad option based on the discussions I've had.
@Zarel
Copy link
Member

Zarel commented Oct 13, 2020

I am currently implemented note ID search simply by streaming to regex in JavaScript; this seemed like the least bad option based on the discussions I've had.

I would normally separately store a note ID, and then do a LIKE search in SQL. Was this considered, and if so, why was it rejected?

@AnnikaCodes
Copy link
Collaborator Author

I rejected the idea of a note_ids table because I am not aware of a satisfactory way to extract the IDs from old notes into a table, although we did discuss that as a possible solution for future modnotes.

Or did you mean having another column in the table for the toIDd note, and using a LIKE query on that? That's definitely feasible and would eliminate the need to define our own regex function in SQLite. I'd want to see what @monsanto thinks about that solution, though.

@Zarel
Copy link
Member

Zarel commented Oct 13, 2020

Or did you mean having another column in the table for the toIDd note, and using a LIKE query on that? That's definitely feasible and would eliminate the need to define our own regex function in SQLite.

Yes, that's what I meant.

@monsanto
Copy link
Member

This was suggested for killing the dependency on better-sqlite3. The reason not to do it would be the extra storage space required, but I don't think it really matters either way.

@monsanto
Copy link
Member

monsanto commented Oct 14, 2020

I think I can do fast note ID search with a custom FTS5 tokenizer. This would require that I write a native sqlite extension in C or Rust. I would prefer doing the latter if there are appropriate bindings available. It is unclear how well this would work, but there is the potential that we will get the best of all possible approaches.

Since this would complicate install for users we could have a configuration option for enabling it, like we currently do for ripgrep. If its off we could just disable searching notes entirely, or fallback to slow LIKE %query%.

@monsanto
Copy link
Member

Give this a shot. Make sure you have libsqlite3-dev installed or whatever the equivalent is on your platform. From /native run ./build.sh and sqlite3 ':memory:' < test.sql

If this works then

  • Load fts_id_tokenizer.o
  • Modify the schema to do CREATE VIRTUAL TABLE modlog_fts USING fts5(note, content=modlog, content_rowid=modlog_id, tokenize='id_tokenizer')
  • Whenever you insert, also insert into modlog_fts
  • Match on the note with ... FROM modlog_fts WHERE note MATCH '<query>'

See https://sqlite.org/fts5.html for more information

@AnnikaCodes
Copy link
Collaborator Author

annika@annika-mac ~/p/native (modlog-sql-new) [1]> /usr/local/opt/sqlite/bin/sqlite3 < test.sql 
** ids available: **
hello this is a test
with 1 numbers 2
Heizölrückstoßabdämpfung

** search for thisis: **
hello this is a test

** search for 1numbers2: **
with 1 numbers 2

** search for lrck: **
Heizölrückstoßabdämpfung
annika@annika-mac ~/p/native (modlog-sql-new)>

Looks good to me; I'll update the modlog logic to use it later today.

server/modlog.ts Outdated Show resolved Hide resolved
databases/schemas/modlog-fts.sql Outdated Show resolved Hide resolved
server/modlog.ts Outdated Show resolved Hide resolved
server/modlog.ts Outdated Show resolved Hide resolved
server/modlog.ts Outdated
}

if (userid) {
query += ` AND (userid LIKE '%' || ? || '%' OR autoconfirmed_userid LIKE '%' || ? || '%' OR EXISTS(SELECT * FROM alts WHERE alts.modlog_id = modlog.modlog_id AND userid LIKE '%' || ? || '%'))`;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think SQLite is smart enough to do OR efficiently, the optimal query plan does parallel index scan + ordered merge (see the PM log where I manually applied this optimization). This is also the strategy you would use to search all fields at the same time, so maybe it is worth waiting on a refactor of this function

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How would you advise I refactor it? (All your other suggestions should be done.)

server/modlog.ts Outdated Show resolved Hide resolved
server/modlog.ts Outdated
query += ` WHERE ${roomChecker}`;

if (search.anyField) {
query += ` AND action LIKE '%' || ? || '%'`;
query += ` AND action LIKE ? || '%'`;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this satisfactory? We have a lot of actions that are a combination of two words, like GTS GIVEAWAY. Would they expect a search on "giveaway" to return a GTS GIVEAWAY row?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll post in WAIL.

server/modlog.ts Outdated Show resolved Hide resolved
@monsanto
Copy link
Member

Unfortunately still doesn't work

monsanto@monsanto:~/downloads/pslogs/main$ ~/smogon/pokemon-showdown/tools/modlog/convert --db ./modlog.db --logdir ./modlog --from txt --to sqlite
Converting the text modlog files in ./modlog from txt to sqlite...
(node:9362) UnhandledPromiseRejectionWarning: RangeError: Too many parameter values were provided
    at ModlogConverterTxt.<anonymous> (/mnt/ssd1/smogon/pokemon-showdown/tools/modlog/converter.js:546:40)
    at ModlogConverterTxt.sqliteTransaction [as insertionTransaction] (/mnt/ssd1/smogon/pokemon-showdown/node_modules/better-sqlite3/lib/transaction.js:58:24)
    at insertEntries (/mnt/ssd1/smogon/pokemon-showdown/tools/modlog/converter.js:578:10)
    at ModlogConverterTxt.toSQLite (/mnt/ssd1/smogon/pokemon-showdown/tools/modlog/converter.js:597:47)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:9362) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:9362) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
monsanto@monsanto:~/downloads/pslogs/main$ ~/smogon/pokemon-showdown/tools/modlog/convert --db ./modlog.db --logdir ./modlog --from txt --to sqlite
Converting the text modlog files in ./modlog from txt to sqlite...
(node:9410) UnhandledPromiseRejectionWarning: SqliteError: table modlog_fts already exists
    at new ModlogConverterTxt (/mnt/ssd1/smogon/pokemon-showdown/tools/modlog/converter.js:533:18)
    at Function.convert (/mnt/ssd1/smogon/pokemon-showdown/tools/modlog/converter.js:684:22)
    at Object.<anonymous> (/mnt/ssd1/smogon/pokemon-showdown/tools/modlog/convert:45:17)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
    at internal/main/run_main_module.js:17:47
(Use `node --trace-warnings ...` to show where the warning was created)
(node:9410) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:9410) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

@AnnikaCodes
Copy link
Collaborator Author

Hm, I don't know if that is FTS related. Fixed it, though!

@monsanto
Copy link
Member

Did you forget to push your fix?

@AnnikaCodes
Copy link
Collaborator Author

yeah lmao

server/modlog.ts Outdated
if (!stream) throw new Error(`Attempted to write to an uninitialized modlog stream for the room '${roomid}'`);
writeSQL(entries: Iterable<ModlogEntry>) {
for (const entry of entries) {
this.insertionTransaction({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This creates N transactions instead of inserting N inside 1 transaction

@monsanto
Copy link
Member

  • I'm relatively confident in this plan of action and intend to merge this soon.

  • Let's just remove the indexes for now, the base schema is sound, and since there won't be any querying for now we can just hold off. Having the dependency in will let me merge mia's work under an experimental flag.

  • Like I mentioned on mia's PR, it isn't a good idea to have IF NOT EXISTS on the SQL. The initial schema code needs to run exactly once, and then after that migrations need to run exactly once.

  • I would make the Config usesqlitemodlog instead of nosqlitemodlog and default to false. We don't want developers not looped into this feature & other servers to be aware of our work until it is ready for the prime time.

  • The converter (and maybe other things at some point?) need to be able to import the Modlog class without it trying to open the modlog at databases/modlog.db.

If you handle the last two, I can handle the other two, and we can merge.

@AnnikaCodes
Copy link
Collaborator Author

I did the last two.

@monsanto
Copy link
Member

Fine to merge, need to install extra dependencies, modify config, and hotpatch modlog

@AnnikaCodes
Copy link
Collaborator Author

One sec. I don't think hotpatching modlog directly will work now that we construct Modlog in rooms.ts.

@AnnikaCodes
Copy link
Collaborator Author

Okay whoever deploys needs to hotpatch chat first (to load the new hotpatching code) and then hotpatch modlog

@monsanto
Copy link
Member

That is a nasty hack, it would be nice if a follow-up commit better isolated the modlog from /hotpatch

@AnnikaCodes
Copy link
Collaborator Author

Yes, once we restart and can depend on Rooms itll be simpler. I'd personally be inclined to put the MODLOG_PATH and stuff in Config instead but our precedent with these sorts of things is to use a const at the top of a file so I dont know if there's a reason we do that instead. Maybe to avoid cluttering config.js?

@monsanto
Copy link
Member

I don't think you need to export these at all, they are implementation details that /hotpatch should not be aware of. The process manager lines above also fall under that umbrella. A better implementation strategy would be for modules that support hotpatch to come with methods to reload themselves.

@AnnikaCodes
Copy link
Collaborator Author

Sure, that sounds good. Id rather do that a separate commit though.

@monsanto monsanto merged commit 2f130e8 into smogon:master Oct 30, 2020
hsahovic added a commit to hsahovic/Pokemon-Showdown that referenced this pull request Nov 1, 2020
* Gigantamax Melmetal is unreleased

* Unskip passing validator test

* Remove /roomwhitelist from /roomhelp (smogon#7547)

* CommandContext: Make requireRoom support specifying a room (smogon#7549)

* Improve Chat.toDurationString

- Default precision is now 3.

  (Instead of "3 months 25 days 17 hours 46 minutes 40 seconds", it'll
	say "3 months 25 days 17 hours". You can still set the precision to
	`Infinity` if you actually prefer that.)

- Now displays "forever" for Infinity or overflow durations

- No longer skips blank precision levels

  (Shows "3 hours 0 minutes 10 seconds" instead of
	"3 hours  10 seconds")

* Mafia: Use new requireRoom API (smogon#7552)

* Youtube: Persist interval time (smogon#7550)

* Use new requireRoom API in trivia and scavs (smogon#7553)

* Publish 0.11.3 to npm

PS's sim engine is now available on npm!

sim/README.md describes how to use it:

https://github.com/smogon/pokemon-showdown/blob/master/sim/README.md

* Fix typo in sim/README.md

* Update OM banlists

* Random Battle improvements

* Validator: Reject sets with the Gigantamax flag that cant Gmax

* Gen 7: Random Battle updates

* Fix bug in toDurationString precision

Fixes smogon#7554

* Support replay URLs in /join (smogon#7526)

* Remove Battle of Legends

* Add Pikachu-Alola event

* Add legendaries to 1v1 & 2v2 banlists

* Remove Battle Stadium Series 6

* Consolidate Neutralizing Gas tests; add Gluttony/Slow Start NGas tests

* Clarify Neutralizing Gas + Imposter test

* Moderation: Improve modlog entry for /rangeban

* Validate timeout durations (smogon#7556)

* Add Crown Tundra Pokemon

TODO: Learnsets

* Add VGC 2020 mod

* Add VGC 2021 format

* Update hidden ability legality

* Missed this file in 42e918a

* Add new moves

* Add move descriptions

* Remove Dynamax Ubers Clause from Ubers

* Fix oversights from adding Crown Tundra DLC (smogon#7559)

* Add activation messages for Curious Medicine

credits marty

* Prevent Mega Rayquaza in gen 8

* Formats: Update banlists

* Let Rayquaza Mega Evolve in National Dex formats

* Crown Tundra: Add and Update Learnsets

It was mentioned that theres some lingering issues that existed
before this update with some pokemon not having Steel Beam/Draco Meteor
that should. I'm noting this here so its not forgotten.

* Update National Dex

* Fix typo in ability text

* Fix another typo

* Monotype: Unban Calyrex-Ice and Calyrex-Shadow

* Abilities: Fix Grim Neigh typo (smogon#7561)

* Fix Thunderous Kick

* Crown Tundra Learnsets: Add Missing Moves

My script had a flaw where it would not add entires for moves that
a pokemon did not learn previously (eg: Electric Terrain Tapu Koko,
Mystical Fire Latios, Close Combat Blaziken). This fixes this issue.

* Fix Moltres's stats (smogon#7562)

Apparently they got overwritten with galars counterpart

* National Dex: Ban Calyrex-Ice and Calyrex-Shadow

* Camomons: Ban Power Construct

* Fix Steel Beam error in learnsets

* Update 2v2 Doubles

* Fix As One attribution text

* Learnsets: Add new event data

* Validator: Allow Hidden Ability Entei/Raikou/Suicune in Gen 8 natively (smogon#7563)

* Add new aliases

* 2v2: Unban Kyurem-Black

* Prevent As One from being copied or removed

* Fix Eerie Spell

* Update obtainable items

Haven't seen confirmation of Soul Dew yet.

* Release the berries

* Show Genesect forme in Team Preview

* Implement As One correctly

* Add new Random Battle sets

* STABmons: Ban Lovely Kiss

* CAP: Unban Clefable

https://www.smogon.com/forums/posts/8635680/

* Fix crash in Punishments#autolock

We should be destroying a user's personal rooms _after_ making a modlog entry.

* As One cannot be suppressed, acquired, or removed

* Soul Dew is available

* Add Anything Goes ladder

* Add As One entry message

* Fix Dragon Ascent Rayquaza validation

* Monotype: Ban Calyrex-Shadow

* Update learnsets

Added legendary dynamax events.
Removed multiple level up entries.
Copy corrections to VGC20 mod.

* 1v1: Ban Magearna and Marshadow

* Convert VGC 2020's mod to a pre-DLC2 mod (smogon#7564)

* Add temporary format for DLC 1 metagame

* Add thread for VGC 2021

* Add Regigigas and Poipole events

* Monotype: Ban Zygarde

* Add Tundra Tourney (smogon#7565)

* Move Battlesearch to its own file (smogon#7481)

* DOU: Ban Jirachi, Melmetal, Dark Urshifu, Swagger

https://www.smogon.com/forums/threads/np-ss-dou-stage-5-one-more-time-jirachi-melmetal-urshifu-single-strike-swagger-quickbanned.3672010/post-8636825

* Update metagame threads

* Update Inheritance bans

* Add The Studio chat plugin (smogon#7542)

* Improve sim readme

* Clean up imports

A lot of our code for child processes doesn't really follow our
original standards. This refactors them back to work the way they
were intended to.

* Micle Berry is obtainable

* Add event Porygon

* Prevent Abilities from copying As One as well

* Battlesearch: fix crash in child processes

* Restrict Calyrex-Ice and Calyrex-Shadow correctly

* Fix Crown Tundra Pokedex validation (smogon#7573)

* Update descriptions

* NatDex Monotype: Ban Calyrex formes and Dragapult

* Tools: Modernize modlog entries for blacklists

* Calculate natures with 16-bit truncation (smogon#7540)

Also fixes Let's Go! which wanted to override these but couldn't.

* Fix typo

* Ignore As One boosts when already maxed out (smogon#7574)

* NFE: Ban Sneasel

* Add gift Toxel event data

* The Studio: Fix crash

* The Studio: Allow finding recs by artist/user name (smogon#7578)

* Monotype: Ban Calyrex-Ice and Genesect

* Ban Japanese Gen 1 Events in Int Formats: Part 2 (smogon#7581)


Co-authored-by: Guangcong Luo <guangcongluo@gmail.com>

* Ban Gen 1 Japan-only event moves

Fixes smogon#7516

* Update Lunar Dance to Gen 8 mechanics (smogon#7576)

* Random Doubles Updates (smogon#7569)

* Random Battle updates

* Rulesets: Fix crash in CCAPM2 (smogon#7582)

* Allow Randdubs Power Construct Zydog (smogon#7583)

* Add Overflow Stat Clause

* Camomons: Ban Dragonite & Kartana

* Move server/'s global variables out of index.ts (smogon#7585)

* AAA: Ban Kartana & Pheromosa

* Connections: Track current chat page (smogon#7522)

* Fix behavior of /faq with no arguments

* Studio: Handle Net errors better (smogon#7586)

* 1v1: Ban Dragonite

* Metronome Battle: Update ability banlist (smogon#7587)

* Youtube: Properly check permissions (smogon#7590)

* Chatlog: Use new username html tag (smogon#7519)

* Mix and Mega: Restrict Zygarde-C

* Add client text data

This syncs data/text to exactly match the client's data/text, in
preparation for them to be merged. The server's data/text will be
canonical, moving forward:

Relevant changes:

- A new file `data/text/default` has been added, for battle messages
  not associated with a move/item/ability.

- As One (Glastrier) and As One (Spectrier) should not have a start
  message; only As One itself.

- Hidden Power's `realMove` property does not belong in data/text
  and has been removed (it's still in data/moves where it belongs).

* Random Battle improvements

* /show: Throttle requests (smogon#7589)

* Make Eerie Spell's secondary effect secondary (smogon#7575)

* Youtube: Cache requested video data (smogon#7593)

* Indicate pending promises in /eval (smogon#7592)

* Remove sim/global-variables.d.ts

The sim no longer uses any global variables, so this can and should be
removed.

`server/global-variables` has also been cleaned up, since I'm working
on this.

* National Dex BH: Ban Electrify

https://www.smogon.com/forums/threads/national-dex-bh.3658587/page-10#post-8640772

* ZU: Ban Combusken

https://www.smogon.com/forums/threads/np-zu-stage-2-turn-it-again-combusken-quick-banned-77.3668115/page-4#post-8640782

* Remove last vestiges of tslint

* Fix Custom Rules Error (smogon#6811)

`/challenge [Gen 8] OU @@@ +Reshiram` failed earlier, since the rule wasn't trimmed.

* Improve custom rule validation

Stray spaces are now consistently allowed in `/tour rules` and
`/challenge`, but are not allowed in `formats.ts`.

Improves smogon#6811

* Make /clearstatus log to Staff room (smogon#7557)

`/forcerename` and other global punishments do this

* sendReplyBox: fix interaction with hidelines (smogon#7577)

* Chatfilters: Fix reasons displaying as undefined (smogon#7579)

* CommandContext: Add a method for getting roomgames (smogon#7531)

* Helptickets: Add button for the reporter's modlog (smogon#7560)

As per (this suggestion)[https://www.smogon.com/forums/threads/staff-suggestions-bugs.3514540/page-17#post-8634198].

* Random Doubles: Fix Regieleki

* Hosts: Support displaying shared IPs (smogon#7568)

* Punishments: Make rangelocks persistent (smogon#7545)

This solves the issue with yearlocks disappearing.

* Fix Slow Start's interaction with Neutralizing Gas (smogon#7580)

* Fix G-Max moves not showing up in movesearch (smogon#7555)

Happened because G-Max moves had move.isNonstandard as 'Gigantamax'.

* Support banning users from using groupchats (smogon#7558)

* Move Genesect and Naganadel to Uber

* Genesect formes should also be Uber

* Update National Dex UU threads

* M&M: Update bans and restrictions

* Chatlog: Carry opts over when switching days (smogon#7584)

* Fix G-Max Depletion (smogon#7571)

* Chat plugins: Make viewing source respect /permissions

* Fix Neutralizing Gas interactions

* Include groupchat bans in /punishments

* Improve error for Japan-only event moves

Thanks Plague Von Karma for help with wording!

Refs smogon#7581

* Reorganize README

The README has been split up so guides for PS's different use-cases are
easier to find.

* Chatlog: Allow non-trusted secret room ROs to view logs (smogon#7597)

* Ticketbans: Use the user object (smogon#7596)

* Improve documentation

Fixes smogon#7602

Also adds some other stuff, perhaps most notably why we don't use
package-lock so you don't have to dig for 2e85de3

* Studio: Only request YT video data once (smogon#7595)

* Add Doubles DLC 1 format

* Move natures into their own file (smogon#7601)

* BH: Add Dynamax Clause

* Update devDependencies

The newest `@types/node` fixes the `assert.strict.equal` deprecation
issue, so I'm updating more frequently than usual.

* Validate Natures in tests

(There's no need to validate natures somewhere that has an actual
performance impact.)

* Fix Hold Hands' num (smogon#7603)

* Add Galarica Wreath

* ANOTD: Change tagline to quote

Requested by Anime and Manga staff

* Add missing Trainer avatars

* Trivia: Document /trivia move

* National Dex Monotype: Unban Arena Trap

* Moderation: Actually make groupchatbans hotpatchable

* Moderation: Remove whitespace

* Helptickets: Properly quote and escape button HTML

* Add Berserk to the Berserk sim test

* Monotype: Update bans

https://www.smogon.com/forums/threads/ss-monotype-metagame-discussion-crown-tundra.3672167/page-3#post-8642660

* Fix Overflow Stat Clause and turn it into a mod (smogon#7604)

* Fix Ripen

* Users: Don't merge unregistered names across IPs

Fixes smogon#7594

* Don't report multiple punishments for a single room (smogon#7606)

* Add Pikachu-World event

* Add event Milcery

* National Dex Monotype: New bans and unbans (smogon#7608)

* AAA: Ban Dragapult, Dragonite, and Magearna

* Inheritance: Ban Regieleki and restrict Butterfree

* Remove VGC 2020 ladder

* Fix permission checks for global promotions

* Rename DLC 1 formats

* Modlog: Support logging to a SQLite database (smogon#7513)

* Modlog: Support logging to a SQLite database

Co-authored-by: Christopher Monsanto <chris@monsan.to>

* Modlog: Fix crash in writing global modlog

* Fix API for writing to the global modlog

* Trivia: Prevent stalemates in Infinite mode

* Update OU Sample Teams link

* Display the announcement whith /announcement (smogon#7612)

* Don't allow forcerenamed usernames to be reused (smogon#7609)

* Random Battle: Minor updates

* DOU DLC1: Fix banlist

* Improve and number design standards

* Modlog: Disallow duplicates in ModlogEntry#alts

* DOU: Ban Marshadow, Shadow Tag

https://www.smogon.com/forums/threads/np-ss-dou-stage-5-one-more-time-jirachi-melmetal-urshifu-single-strike-swagger-quickbanned-marshadow-shadow-tag-quickbanned.3672010/post-8644210

* Build: Update dependency check

* Trademarked: Update bans

* Fix Streams bug

It turns out 001f98b was wrong.

When urkerab asked why it `peek` wasn't awaited:

smogon@e91c4c5#commitcomment-41364837

The answer was because clearing the buffer after peeking needed to
happen synchronous: if the buffer is written to after peeking but
before the buffer is cleared, that write is lost forever.

This just goes to show, if you do something subtle enough to require
type assertions, you should probably add a comment about what's going
on.

Fixes smogon#7605

This also removes `BattleStream#start()` which is completely useless
API complication. A better implementation would properly forward
crashes between streams (maybe `pipeTo` should do this) but as it
stands, it's not doing anything.

* Improve "click here" error message

* Add November's OMotM, LCotM and RoA Spotlight (smogon#7615)

* NFE: Ban Haunter and Pawniard

* Update Doubles tiers

* CAP: Fix Mega Crucibelle being allowed

* Fix [Gen 3] Doubles OU

* Scalemons: Add Overflow Stat Mod

* November tier update

* Update NU-legal Pokemon

* Update National Dex tiers

* CODEOWNERS: Add chaos to anything SQLite related

* Config: Move Bot rank below Driver  (smogon#7617)

* Revamp Gen 2 Random Battle (smogon#7610)

* Fix /randbats interaction with Gen 2 sets

* Remove unused definitions

* Modlog: Avoid optional properties in ModlogEntry  (smogon#7613)

* Modlog: Avoid optional properties in ModlogEntry

* Use a type

* Make IP nullable

* Add NOT NULL constrains

* Fix typo

* Better handle races when reading Streams

* Mark other Genesect formes as unreleased in DLC1

* Gen 2 Random: Fix Rest + Sleep Talk

* Add new PU bans

* Gen 2 Random: Fix typo

* NU: Unban Drought

Also updated tier threads.

Co-authored-by: Kris Johnson <11083252+KrisXV@users.noreply.github.com>
Co-authored-by: Leonard Craft <leonardcraft64@gmail.com>
Co-authored-by: Mia <49593536+mia-pi-git@users.noreply.github.com>
Co-authored-by: Guangcong Luo <guangcongluo@gmail.com>
Co-authored-by: iscke <frumgerth@gmail.com>
Co-authored-by: The Immortal <the_immortal123@live.com>
Co-authored-by: HoeenHero <HoeenCoder@users.noreply.github.com>
Co-authored-by: Annika <56906084+AnnikaCodes@users.noreply.github.com>
Co-authored-by: Annika <hehe@doesntexist.com>
Co-authored-by: Instruct <66930476+xInstruct@users.noreply.github.com>
Co-authored-by: Marty-D <Marty-D@users.noreply.github.com>
Co-authored-by: Quinton Lee <quivistis@gmail.com>
Co-authored-by: LegoFigure11 <24732684+LegoFigure11@users.noreply.github.com>
Co-authored-by: urkerab <urkerab@users.noreply.github.com>
Co-authored-by: May Evans <36418502+PlagueVonKarma@users.noreply.github.com>
Co-authored-by: ACakeWearingAHat <45981036+ACakeWearingAHat@users.noreply.github.com>
Co-authored-by: VineST <alek.malesevic@yahoo.com>
Co-authored-by: Konrad Borowski <konrad@borowski.pw>
Co-authored-by: PartMan <47669599+PartMan7@users.noreply.github.com>
Co-authored-by: Charlie Kobayashi <sparkychildcharlie@gmail.com>
Co-authored-by: edcrfv <70171487+edcrfv0@users.noreply.github.com>
Co-authored-by: DarkPhoenix911 <64982718+DarkPhoenix911@users.noreply.github.com>
Co-authored-by: Christopher Monsanto <chris@monsan.to>
Co-authored-by: Distrib <theodelhay@orange.fr>
Co-authored-by: Annika <annika0uwu@gmail.com>
Quanyails pushed a commit to Quanyails/Pokemon-Showdown that referenced this pull request May 12, 2021
* Modlog: Support logging to a SQLite database

Co-authored-by: Christopher Monsanto <chris@monsan.to>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants