Why do I define my Queries, Data, and Mutation as Singleton when using GraphQL in .NET Core?

Why do I define my Queries, Data, and Mutation as Singleton when using GraphQL in .NET Core?

From the doc’s dependency injection page:

public void ConfigureServices(IServiceCollection services) {   services.AddSingleton<IDependencyResolver>(s => new FuncDependencyResolver(s.GetRequiredService));    services.AddSingleton<IDocumentExecuter, DocumentExecuter>();   services.AddSingleton<IDocumentWriter, DocumentWriter>();    services.AddSingleton<StarWarsData>();   services.AddSingleton<StarWarsQuery>();   services.AddSingleton<StarWarsMutation>();   services.AddSingleton<HumanType>();   services.AddSingleton<HumanInputType>();   services.AddSingleton<DroidType>();   services.AddSingleton<CharacterInterface>();   services.AddSingleton<EpisodeEnum>();   services.AddSingleton<ISchema, StarWarsSchema>(); } 

At the beginning of the docs:

The library resolves a GraphType only once and caches that type for the lifetime of the Schema.

While I understand that these are more like DTOs in which they hold values or their class content doesn’t change at all… Why do I specify them as singleton instead of just letting them get instantiated?

Why are bulk multi-column key queries so slow in MySQL?

(For this question, I am using AWS/Aurora MySQL with a reasonably-spec’d RDS instance)

Consider the following schema:

Table T:     col0: the usual autoincrement primary key     col1: varchar     col2: varchar     col3: varchar     col4...N: various data 

Consider that there is a unique index on:

<col1, col2, col3> 

And a non-unique index on:

<col1, col2> 

And consider the following query:

SELECT * FROM T WHERE     (col1 = 'val1' AND col2 = 'id1') OR     (col1 = 'val2' AND col2 = 'id2') OR     ...     (col1 = 'valN' AND col2 = 'idN'); 

I would (perhaps naively) expected MySQL to figure out that each element of the OR set matched the (non-unique) index, and performed the query in the way it would have if I had said:

WHERE col0 in (v1, v2, ... , vN) 

But it doesn’t seem to do that: the timing for these two queries is WAY OFF, on the order of 10x slower for the “or of ands” query. EVEN WITH the secondary key lookup, and the fact that it’s a string column lookup, 10x seems a bit severe. Note that EXPLAIN claims to be using the correct/expected index whether I specify (col1, col2) or (col1, col2, col3)

Please note also that:

SELECT * from T WHERE     col1 in (list1) AND     col2 in (list2); 

Is also slow when there are a lot of different values in list1 and list2. Doing an “and” for the three columns is almost intractably slow.

Perhaps not surprisingly, this query works better than the “or of ands” when list1 is of length 1.

Multiples Queries por Router en Nodejs

Estoy hacinedo esto para tratar de mandar varios queries de un solo get, pero no sé porque me sale esto. No se si es posible lo que planteo.

router.get('/profile', isLoggedIn, async(req, res) => {   const admins = await pool.query('Select * from Users where admin  = 1');   const links = await pool.query('Select * from links order by created_at desc');   res.render('links/profile', {links}, {admins});  });

Si uso un solo query, es decir si le mando solo admins o solo links si pasa todo.

express-handlebars/lib/utils.js:26 callback(null, value);

TypeError: callback is not a function

JSON com multiplas queries

Queria gerar um JSON que mostrasse uma lista de alunos que faltaram em uma respectiva aula. O JSON ficaria assim?

{"Faltas":[{"aulaID": 1, "alunoID": [1, 2, 3]}]} 

E eu preciso utilizar essas queries para gerá-lo:

SELECT AulaID, AlunoID FROM FaltaAula ORDER BY AulaID, AlunoID  SELECT Data, DisciplinaID, AlunoID FROM FaltaDupla ORDER BY Data, DisciplinaID, AlunoID  SELECT Data, AlunoID FROM FaltaDia ORDER BY Data, AlunoID 

Como posso fazer isso, levando em conta que as tabelas FaltaAula, FaltaDia e FaltaDupla estão relacionadas?

Eu havia feito dessa maneira:

$  query = $  database->query( "SELECT aulaID, GROUP_CONCAT(alunoID) AS alunoID FROM FaltaAula  GROUP BY aulaID ORDER BY aulaID"); $  listaFaltas = array(); while ($  row = $  query->fetch(PDO::FETCH_ASSOC)) {     $  listaFaltas[] = array('aulaID' => $  row['aulaID'], 'alunoID' => explode(',', $  row['alunoID'])); } echo json_encode($  listaFaltas); 

Mas, tem dois erros, um que o GROUP_CONCAT transforma o alunoID em string e eu preciso que ele seja inteiro, e o outro erro é que eu estou utilizando apenas da tabela FaltaAula, quando na verdade preciso utilizar as três.

OBS: Estou utilizando PDO.

MariaDB replication and cross database queries

I need to improve backup of databases that won’t load production server. I read that good solution to do that is to set database replication and do mysqldumps on slave server.

But description of “replicate_do_db” says that updates won’t work with cross-database queries. And here is a problem – I have a lot of PHP apps (few of them are really old) so I have no guarantee that they not use this kind of queries. And I don’t want to have out-of-sync databases…

Is there any alternative? Or just use replication only for well-known apps, and mydumper/mysqldump for other?

I know that Percona XtraBackup exist but I want to have backups in .sql format.

Log Elasticsearch queries (and possibly provide analytics)

I have an Elasticsearch instance (on AWS) and I want to log the search queries and have a way of checking the most frequent searches, the searches that returned 0 results etc.

I am new to Elasticsearch and I am not sure if there is anything specific already implemented or if I have to implement it on my application.

To sum up, I need two things:

  1. Log search queries
  2. Provide basic analytics

KQL simplification of multiple string.contains queries

For SharePoint search, I create a KQL query that, among other things, sometimes checks whether an entity has one of several interesting substrings appearing in one particular property.

The property itself is a comma-separated list of integral IDs, and every atom of my body dislikes this solution, but apparently it works and at this point in time, it’s what I’m working with.

So, we have the property ReallyLongAndCumbersomeName that can look something like 245, 2451, 21, 96612, 5215.

And so a query can contain this:

(ReallyLongAndCumbersomeName:29 OR ReallyLongAndCumbersomeName:30 OR ReallyLongAndCumbersomeName:31 OR ReallyLongAndCumbersomeName:32 OR ReallyLongAndCumbersomeName:33 OR ReallyLongAndCumbersomeName:34 OR ReallyLongAndCumbersomeName:20 OR ReallyLongAndCumbersomeName:35 OR ReallyLongAndCumbersomeName:36 OR ReallyLongAndCumbersomeName:21 OR ReallyLongAndCumbersomeName:427382 )

So the question is, can I simplify this to something like

ReallyLongAndCumbersomeName:(29 OR 30 OR 21 OR 32 OR 33 OR 34 OR 20 OR 35 OR 36 OR 21 OR 427382)?