Skip to content
This repository has been archived by the owner on Oct 13, 2024. It is now read-only.

Cache dropdown contents until admin makes them dirty (custom, org, for example) #27

Closed
ctrager opened this issue Dec 9, 2020 · 29 comments

Comments

@ctrager
Copy link
Owner

ctrager commented Dec 9, 2020

This is pulling up the issue create form

SQL 1:/check_user_permissions/ select * from sessions
inner join users on se_user = us_id
where se_id = '46db6f69-dad5-49de-b9d3-c4e15d4724f4'; /*check_user_permissions */
SQL 2:select og_id, og_name from organizations where og_is_active = true union select 0, '[None]' order by og_name
SQL 3:select us_id, us_username from users where us_is_active = true order by us_username
SQL 4:select c1_id, c1_name from custom_1 where c1_is_active = true order by c1_name
SQL 5:select c2_id, c2_name from custom_2 where c2_is_active = true order by c2_name
SQL 6:select c4_id, c4_name from custom_4 where c4_is_active = true order by c4_name
SQL 7:select og_id, og_name from organizations where og_is_default is true order by og_name limit 1
SQL 8:select c1_id from custom_1 where c1_is_default is true order by c1_name limit 1
SQL 9:select c2_id from custom_2 where c2_is_default is true order by c2_name limit 1
SQL 10:select c4_id from custom_4 where c4_is_default is true order by c4_name limit 1
layout_si

@ghost
Copy link

ghost commented Dec 10, 2020

Maybe use EF. Can cache.
Or some service with manual memory caching.

@ctrager
Copy link
Owner Author

ctrager commented Dec 10, 2020

The lifecycle of the app, it's like a normal C# program. When it starts running the static classes like bd_util, bd_db, bd_config, and bd_session as well as Program and Startup a constructed and stay alive as singletons during the entire program. Any of them with global static variables, those variables serve as a cache.

The one thing to keep in mind is that the global static variables can be accessed by multiple threads, so need to be protected.
Look especially at bd_session, which I'm not using for anything, but I created it because I thought I was using it.

So, in other words, HOW to cache is not an issue.

What is an issue is that the logic for maintaining the cache is just one more thing that can be buggy, one more thing to break, so I don't want to do it if the benefit is small.

@ghost
Copy link

ghost commented Dec 10, 2020

That's why I mentioned EF as it encapsulates all the work with cache.

@ctrager
Copy link
Owner Author

ctrager commented Dec 10, 2020

Right, if ALL our database updates were done via EF, then EF caching would make sense, but it's either all or nothing. For EF to cache correctly we would have to do all updates via EF.
I debating whether to use EF or not during this rewrite but I just decided I wasn't interested. Maybe it would have been better, but I'm still happy with my choice.

@ctrager
Copy link
Owner Author

ctrager commented Dec 10, 2020

For your english practice:
http://blogs.tedneward.com/post/the-vietnam-of-computer-science/

@ghost
Copy link

ghost commented Dec 10, 2020

So many letters. 😄

@ghost
Copy link

ghost commented Dec 10, 2020

@ctrager
Copy link
Owner Author

ctrager commented Dec 10, 2020

Yeah, maybe the codebase would be better if I did the db stuff a different way.
what is the purpose of Where(x => true) in your example?

@ctrager
Copy link
Owner Author

ctrager commented Dec 10, 2020

And that tool you are using where you can type C# code instead of sql into it, is there something like that available for linux?

@ctrager
Copy link
Owner Author

ctrager commented Dec 10, 2020

"Bugs" is an EF model?

@ghost
Copy link

ghost commented Dec 10, 2020

Yeah, maybe the codebase would be better if I did the db stuff a different way.
what is the purpose of Where(x => true) in your example?

The predicate is always true, get all records.

@ghost
Copy link

ghost commented Dec 10, 2020

And that tool you are using where you can type C# code instead of sql into it, is there something like that available for linux?

https://www.linqpad.net/

@ghost
Copy link

ghost commented Dec 10, 2020

@ctrager
Copy link
Owner Author

ctrager commented Dec 10, 2020

@ghost
Copy link

ghost commented Dec 10, 2020

https://forum.linqpad.net/discussion/1983/roadmap-for-cross-platform-ubuntu-linux

I think EF with console logging will show SQL.

@ctrager
Copy link
Owner Author

ctrager commented Dec 10, 2020

@ctrager
Copy link
Owner Author

ctrager commented Dec 10, 2020

I'm timing how long it takes Issue.cshtml.cs OnGet, and it's usually about 20 milliseconds, so there's no point in trying to optimize it more, it's already so fast.

@ctrager ctrager closed this as completed Dec 10, 2020
@ghost
Copy link

ghost commented Dec 10, 2020

I don't understand why you are sending this to me. I don't understand how it relates to what we've talked about. Please explain.

These issues are addressed in the article. I thought this might be interesting.

Object systems are typically characterized by four basic components: identity, state, behavior and encapsulation. Identity is an implicit concept in most O-O languages, in that a given object has a unique identity that is distinct from its state (the value of its internal fields)–two objects with the same state are still separate and distinct objects, despite being bit-for-bit mirrors of one another. This is the “identity vs. equivalence” discussion that occurs in languages like C++, C# or Java, where developers must distinguish between “a == b” and “a.equals(b)”.

From article.

@ghost
Copy link

ghost commented Dec 10, 2020

I'm timing how long it takes Issue.cshtml.cs OnGet, and it's usually about 20 milliseconds, so there's no point in trying to optimize it more, it's already so fast.

👍

@ctrager
Copy link
Owner Author

ctrager commented Dec 10, 2020

Sorry, I don't understand how the quote about identity relates to decisions about how to code Budoco.

@ghost
Copy link

ghost commented Dec 10, 2020

This applies to EF or ORM.
Although the article shows the problem, but, as far as I know, this is solved.

@ctrager
Copy link
Owner Author

ctrager commented Dec 10, 2020

"this is solved". WHAT is solved? I still don't understand how this discussion relates to decisions about how to code Budoco.

@ghost
Copy link

ghost commented Dec 10, 2020

In the article, as I understand it, it was said that it is difficult to unambiguously map the database model to objects. Since objects have unique links.

image

image

@ghost
Copy link

ghost commented Dec 10, 2020

In the second case, "Name" became a unique key as in the database.

@ctrager
Copy link
Owner Author

ctrager commented Dec 10, 2020

You read the article more carefully than me!

I dislike having to learn an API (EF) to write a language that I already know how to write (SQL).

The abstraction is super leaky, like N+1, or any query that returns something that isn't a "User", but rather just a column from the users table, or a join between two tables.

If I just want everything LINQ'ified, then maybe Dapper would be good, but 99% of what i do is just foreach (DataRow dr.... so why would I bring in another library just so that it loads the DataTable results into a different kind of collection?

There are some things I like about ORMs:

  • a Migration system for free. But it's not too hard to write one. A dozen lines of code. But, I still have to write and test it.

  • Putting together a complex SQL statement at runtime. Rails ActiveRecord is really good for this. Doing it with string the way I did it in BugTracker.NET, that's messy. But Budoco does way way way less with dynamic sql, and the most complicated sql is outside the C# code - the sql that's in the external queries and reports. The whole culture of Budoco/BugTracker.NET is YOU HAVE TO LIKE WRITING SQL.

@ghost
Copy link

ghost commented Dec 10, 2020

The abstraction is super leaky, like N+1, or any query that returns something that isn't a "User", but rather just a column from the users table, or a join between two tables.

Don't use object graph.

All libraries over SQL solve other problems in parallel: caching, code duplication, security ...
Of course, all this is not unambiguous.

@ghost
Copy link

ghost commented Dec 10, 2020

@ctrager
Copy link
Owner Author

ctrager commented Dec 10, 2020

The solve all problems except for the 1,400 open issues against EF.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant