On Friday, I wrote about why I love using flat text files instead of a database for my projects. One of the more common questions I got was how I search for things, and the performance impacts of doing so. The truth is… I don't! The structure of my file system—lots of small, sensibly named files—means that I almost never have to search for anything. Let's take the Lean Web Club for example. Every user has a JSON file with their hashed password, account status (active or cancelled), and an array of their bookmarked lessons. The file name is their username/email address.
If I want to check if a user has an active account, I read their file, parse it to JSON, and check the
On any particular lesson, I need to know if the lesson is currently bookmarked or not so I can show the correct I can use PHP to check if the page ID is in the
When a user logs in, I create a cryptographically random token. I set that token as a cookie, and create a file with the token as its name. The file contains the associated email address for the user. On every page load, I check if an auth cookie exists. If it does, I get the associated session file and read it to get the user's email address. I can use that to read their file, check their status, show their bookmarks, and so on. No file? No active session. The only "searching" I really need to do is periodically finding expired token files and deleting them. I include the "created on" date as part of the token (and by extension, file name). Every day, I loop through all of the token files. If the "create on" part of the file name is older than the duration of an active session, I delete the file. I never even need to read the contents. I can imagine certain situations where this kind of setup wouldn't work. But for the types of apps I build, it's simple, absurdly fast, and makes building and maintaining apps so much more simple than maintaining a database. Cheers, Want to share this with others or read it later? View it in a browser. |
Related Post:
- U.S. Airlines’ September 2023 Fuel Cost per Gallon Up 11.4% from August 2023; Aviation Fuel Consumption Up 2.8% from Pre-Pandemic September 2019
- Stop the Storage Shed-nanigans!
- Want the Year’s BEST Recipes? Find 500+ Inside!
- WWE Crown Jewel is Almost Here! Watch the Star-Studded Event with Five Titles on the Line Tomorrow only on Sportsnet+!
- October 2023 U.S. Transportation Sector Unemployment (4.8%) Rises Above the October 2022 Level (3.7%) And the Pre-Pandemic October 2019 Level (2.7%)
0 Komentar untuk "[Go Make Things] What about searching flat files?"