@nina-protocol/nina-db 0.0.101 → 0.0.103

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,18 @@
1
+ /**
2
+ * @param { import("knex").Knex } knex
3
+ * @returns { Promise<void> }
4
+ */
5
+ export const up = function (knex) {
6
+ return knex.schema.table('releases', table => {
7
+ table.string('programId').notNullable().defaultTo(process.env.NINA_PROGRAM_ID);
8
+ });
9
+ };
10
+ /**
11
+ * @param { import("knex").Knex } knex
12
+ * @returns { Promise<void> }
13
+ */
14
+ export const down = function (knex) {
15
+ return knex.schema.table('releases', table => {
16
+ table.dropColumn('programId');
17
+ });
18
+ };
@@ -0,0 +1,18 @@
1
+ /**
2
+ * @param { import("knex").Knex } knex
3
+ * @returns { Promise<void> }
4
+ */
5
+ export const up = function (knex) {
6
+ return knex.schema.table('transactions', table => {
7
+ table.string('programId').notNullable().defaultTo(process.env.NINA_PROGRAM_ID);
8
+ });
9
+ };
10
+ /**
11
+ * @param { import("knex").Knex } knex
12
+ * @returns { Promise<void> }
13
+ */
14
+ export const down = function (knex) {
15
+ return knex.schema.table('transactions', table => {
16
+ table.dropColumn('programId');
17
+ });
18
+ };
@@ -37,8 +37,9 @@ export default class Account extends Model {
37
37
  this.verifications = verifications;
38
38
  }
39
39
  delete this.id;
40
- const followers = await Subscription.query().where('to', this.publicKey).range(0, 0);
41
- this.followers = followers.total;
40
+ // Use count() instead of range(0,0) to avoid temporary object creation
41
+ const followersCount = await Subscription.query().where('to', this.publicKey).count('* as count').first();
42
+ this.followers = parseInt(followersCount.count);
42
43
  };
43
44
  static relationMappings = () => ({
44
45
  published: {
@@ -31,8 +31,9 @@ export default class Hub extends Model {
31
31
  delete this.authorityId;
32
32
  delete this.id;
33
33
  stripHtmlIfNeeded(this.data, 'description');
34
- const followers = await Subscription.query().where('to', this.publicKey).range(0, 0);
35
- this.followers = followers.total;
34
+ // Use count() instead of range(0,0) to avoid temporary object creation
35
+ const followersCount = await Subscription.query().where('to', this.publicKey).count('* as count').first();
36
+ this.followers = parseInt(followersCount.count);
36
37
  }
37
38
  static relationMappings = () => ({
38
39
  authority: {
@@ -10,6 +10,13 @@ import Tag from './Tag.js';
10
10
  import axios from 'axios';
11
11
  import promiseRetry from 'promise-retry';
12
12
  import { customAlphabet } from 'nanoid';
13
+ import promiseRetry from 'promise-retry';
14
+ const ensureHttps = (uri) => {
15
+ if (!uri.startsWith('http://') && !uri.startsWith('https://')) {
16
+ return `https://${uri}`;
17
+ }
18
+ return uri;
19
+ };
13
20
  const alphabet = '0123456789abcdefghijklmnopqrstuvwxyz';
14
21
  const randomStringGenerator = customAlphabet(alphabet, 12);
15
22
  export default class Release extends Model {
@@ -78,10 +85,10 @@ export default class Release extends Model {
78
85
  }
79
86
  let json;
80
87
  try {
81
- json = (await axios.get(metadataAccount.uri.replace('www.', '').replace('arweave.net', 'gateway.irys.xyz'))).data;
88
+ json = (await axios.get(ensureHttps(metadataAccount.uri.replace('www.', '').replace('arweave.net', 'gateway.irys.xyz')))).data;
82
89
  }
83
90
  catch (error) {
84
- json = (await axios.get(metadataAccount.uri.replace('gateway.irys.xyz', 'arweave.net'))).data;
91
+ json = (await axios.get(ensureHttps(metadataAccount.uri.replace('gateway.irys.xyz', 'arweave.net')))).data;
85
92
  }
86
93
  const slug = await this.generateSlug(json);
87
94
  let publisher = await Account.findOrCreate(releaseAccount.authority.toBase58());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nina-protocol/nina-db",
3
- "version": "0.0.101",
3
+ "version": "0.0.103",
4
4
  "description": "",
5
5
  "source": "src/index.js",
6
6
  "main": "dist/index.js",
@@ -42,8 +42,9 @@ export default class Account extends Model {
42
42
  this.verifications = verifications;
43
43
  }
44
44
  delete this.id
45
- const followers = await Subscription.query().where('to', this.publicKey).range(0,0);
46
- this.followers = followers.total;
45
+ // Use count() instead of range(0,0) to avoid temporary object creation
46
+ const followersCount = await Subscription.query().where('to', this.publicKey).count('* as count').first();
47
+ this.followers = parseInt(followersCount.count);
47
48
  }
48
49
 
49
50
  static relationMappings = () => ({
package/src/models/Hub.js CHANGED
@@ -35,8 +35,9 @@ export default class Hub extends Model {
35
35
 
36
36
  stripHtmlIfNeeded(this.data, 'description');
37
37
 
38
- const followers = await Subscription.query().where('to', this.publicKey).range(0, 0);
39
- this.followers = followers.total;
38
+ // Use count() instead of range(0,0) to avoid temporary object creation
39
+ const followersCount = await Subscription.query().where('to', this.publicKey).count('* as count').first();
40
+ this.followers = parseInt(followersCount.count);
40
41
  }
41
42
 
42
43
  static relationMappings = () => ({
@@ -12,6 +12,13 @@ import promiseRetry from 'promise-retry';
12
12
  import { customAlphabet } from 'nanoid';
13
13
  import promiseRetry from 'promise-retry';
14
14
 
15
+ const ensureHttps = (uri) => {
16
+ if (!uri.startsWith('http://') && !uri.startsWith('https://')) {
17
+ return `https://${uri}`;
18
+ }
19
+ return uri;
20
+ };
21
+
15
22
  const alphabet = '0123456789abcdefghijklmnopqrstuvwxyz';
16
23
  const randomStringGenerator = customAlphabet(alphabet, 12);
17
24
  export default class Release extends Model {
@@ -89,9 +96,9 @@ export default class Release extends Model {
89
96
  }
90
97
  let json
91
98
  try {
92
- json = (await axios.get(metadataAccount.uri.replace('www.','').replace('arweave.net', 'gateway.irys.xyz'))).data
99
+ json = (await axios.get(ensureHttps(metadataAccount.uri.replace('www.','').replace('arweave.net', 'gateway.irys.xyz')))).data
93
100
  } catch (error) {
94
- json = (await axios.get(metadataAccount.uri.replace('gateway.irys.xyz', 'arweave.net'))).data
101
+ json = (await axios.get(ensureHttps(metadataAccount.uri.replace('gateway.irys.xyz', 'arweave.net')))).data
95
102
  }
96
103
 
97
104
  const slug = await this.generateSlug(json);
@@ -1,54 +0,0 @@
1
- /**
2
- * @param { import("knex").Knex } knex
3
- * @returns { Promise<void> }
4
- */
5
- export const up = function (knex) {
6
- return Promise.all([
7
- // Accounts table indexes
8
- knex.schema.alterTable('accounts', table => {
9
- table.index('displayName');
10
- table.index('handle');
11
- }),
12
- // Hubs table indexes
13
- knex.schema.raw('CREATE INDEX idx_hubs_handle ON hubs (handle)'),
14
- knex.schema.raw('CREATE INDEX idx_hubs_display_name ON hubs ((data->>\'displayName\'))'),
15
- // Tags table index
16
- knex.schema.alterTable('tags', table => {
17
- table.index('value');
18
- }),
19
- // Releases table indexes for search
20
- knex.schema.raw('CREATE INDEX idx_releases_metadata_name ON releases ((metadata->>\'name\'))'),
21
- knex.schema.raw('CREATE INDEX idx_releases_metadata_artist ON releases ((metadata->\'properties\'->>\'artist\'))'),
22
- knex.schema.raw('CREATE INDEX idx_releases_metadata_title ON releases ((metadata->\'properties\'->>\'title\'))'),
23
- // GIN indexes for JSON fields
24
- knex.schema.raw('CREATE INDEX idx_hubs_data_gin ON hubs USING GIN (data)'),
25
- knex.schema.raw('CREATE INDEX idx_releases_metadata_gin ON releases USING GIN (metadata)')
26
- ]);
27
- };
28
- /**
29
- * @param { import("knex").Knex } knex
30
- * @returns { Promise<void> }
31
- */
32
- export const down = function (knex) {
33
- return Promise.all([
34
- // Drop Accounts table indexes
35
- knex.schema.alterTable('accounts', table => {
36
- table.dropIndex('displayName');
37
- table.dropIndex('handle');
38
- }),
39
- // Drop Hubs table indexes
40
- knex.schema.raw('DROP INDEX IF EXISTS idx_hubs_handle'),
41
- knex.schema.raw('DROP INDEX IF EXISTS idx_hubs_display_name'),
42
- // Drop Tags table index
43
- knex.schema.alterTable('tags', table => {
44
- table.dropIndex('value');
45
- }),
46
- // Drop Releases table indexes
47
- knex.schema.raw('DROP INDEX IF EXISTS idx_releases_metadata_name'),
48
- knex.schema.raw('DROP INDEX IF EXISTS idx_releases_metadata_artist'),
49
- knex.schema.raw('DROP INDEX IF EXISTS idx_releases_metadata_title'),
50
- // Drop GIN indexes
51
- knex.schema.raw('DROP INDEX IF EXISTS idx_hubs_data_gin'),
52
- knex.schema.raw('DROP INDEX IF EXISTS idx_releases_metadata_gin')
53
- ]);
54
- };
@@ -1,80 +0,0 @@
1
- export const up = async (knex) => {
2
- // Add indexes for JSON fields commonly used in search
3
- await knex.raw(`
4
- CREATE INDEX IF NOT EXISTS idx_releases_metadata_artist
5
- ON releases ((metadata->'properties'->>'artist'));
6
- `);
7
- await knex.raw(`
8
- CREATE INDEX IF NOT EXISTS idx_releases_metadata_title
9
- ON releases ((metadata->'properties'->>'title'));
10
- `);
11
- await knex.raw(`
12
- CREATE INDEX IF NOT EXISTS idx_releases_metadata_tags
13
- ON releases ((metadata->'properties'->>'tags'));
14
- `);
15
- await knex.raw(`
16
- CREATE INDEX IF NOT EXISTS idx_releases_metadata_symbol
17
- ON releases ((metadata->'properties'->>'symbol'));
18
- `);
19
- // Add index for hub search
20
- await knex.raw(`
21
- CREATE INDEX IF NOT EXISTS idx_hubs_data_displayname
22
- ON hubs ((data->>'displayName'));
23
- `);
24
- // Add index for post search
25
- await knex.raw(`
26
- CREATE INDEX IF NOT EXISTS idx_posts_data_title
27
- ON posts ((data->>'title'));
28
- `);
29
- await knex.raw(`
30
- CREATE INDEX IF NOT EXISTS idx_posts_data_description
31
- ON posts ((data->>'description'));
32
- `);
33
- // Add indexes for regular fields
34
- await knex.raw(`
35
- CREATE INDEX IF NOT EXISTS idx_accounts_displayname
36
- ON accounts (display_name);
37
- `);
38
- await knex.raw(`
39
- CREATE INDEX IF NOT EXISTS idx_accounts_handle
40
- ON accounts (handle);
41
- `);
42
- await knex.raw(`
43
- CREATE INDEX IF NOT EXISTS idx_hubs_handle
44
- ON hubs (handle);
45
- `);
46
- await knex.raw(`
47
- CREATE INDEX IF NOT EXISTS idx_releases_archived
48
- ON releases (archived);
49
- `);
50
- await knex.raw(`
51
- CREATE INDEX IF NOT EXISTS idx_releases_datetime
52
- ON releases (datetime);
53
- `);
54
- await knex.raw(`
55
- CREATE INDEX IF NOT EXISTS idx_posts_datetime
56
- ON posts (datetime);
57
- `);
58
- // Add composite indexes for common query patterns
59
- await knex.raw(`
60
- CREATE INDEX IF NOT EXISTS idx_releases_archived_datetime
61
- ON releases (archived, datetime);
62
- `);
63
- };
64
- export const down = async (knex) => {
65
- // Remove all created indexes
66
- await knex.raw(`DROP INDEX IF EXISTS idx_releases_metadata_artist;`);
67
- await knex.raw(`DROP INDEX IF EXISTS idx_releases_metadata_title;`);
68
- await knex.raw(`DROP INDEX IF EXISTS idx_releases_metadata_tags;`);
69
- await knex.raw(`DROP INDEX IF EXISTS idx_releases_metadata_symbol;`);
70
- await knex.raw(`DROP INDEX IF EXISTS idx_hubs_data_displayname;`);
71
- await knex.raw(`DROP INDEX IF EXISTS idx_posts_data_title;`);
72
- await knex.raw(`DROP INDEX IF EXISTS idx_posts_data_description;`);
73
- await knex.raw(`DROP INDEX IF EXISTS idx_accounts_displayname;`);
74
- await knex.raw(`DROP INDEX IF EXISTS idx_accounts_handle;`);
75
- await knex.raw(`DROP INDEX IF EXISTS idx_hubs_handle;`);
76
- await knex.raw(`DROP INDEX IF EXISTS idx_releases_archived;`);
77
- await knex.raw(`DROP INDEX IF EXISTS idx_releases_datetime;`);
78
- await knex.raw(`DROP INDEX IF EXISTS idx_posts_datetime;`);
79
- await knex.raw(`DROP INDEX IF EXISTS idx_releases_archived_datetime;`);
80
- };
@@ -1,94 +0,0 @@
1
- export const up = async (knex) => {
2
- // Add indexes for JSON fields commonly used in search
3
- await knex.raw(`
4
- CREATE INDEX IF NOT EXISTS idx_releases_metadata_artist
5
- ON releases ((metadata->'properties'->>'artist'));
6
- `);
7
-
8
- await knex.raw(`
9
- CREATE INDEX IF NOT EXISTS idx_releases_metadata_title
10
- ON releases ((metadata->'properties'->>'title'));
11
- `);
12
-
13
- await knex.raw(`
14
- CREATE INDEX IF NOT EXISTS idx_releases_metadata_tags
15
- ON releases ((metadata->'properties'->>'tags'));
16
- `);
17
-
18
- await knex.raw(`
19
- CREATE INDEX IF NOT EXISTS idx_releases_metadata_symbol
20
- ON releases ((metadata->'properties'->>'symbol'));
21
- `);
22
-
23
- // Add index for hub search
24
- await knex.raw(`
25
- CREATE INDEX IF NOT EXISTS idx_hubs_data_displayname
26
- ON hubs ((data->>'displayName'));
27
- `);
28
-
29
- // Add index for post search
30
- await knex.raw(`
31
- CREATE INDEX IF NOT EXISTS idx_posts_data_title
32
- ON posts ((data->>'title'));
33
- `);
34
-
35
- await knex.raw(`
36
- CREATE INDEX IF NOT EXISTS idx_posts_data_description
37
- ON posts ((data->>'description'));
38
- `);
39
-
40
- // Add indexes for regular fields
41
- await knex.raw(`
42
- CREATE INDEX IF NOT EXISTS idx_accounts_displayname
43
- ON accounts (display_name);
44
- `);
45
-
46
- await knex.raw(`
47
- CREATE INDEX IF NOT EXISTS idx_accounts_handle
48
- ON accounts (handle);
49
- `);
50
-
51
- await knex.raw(`
52
- CREATE INDEX IF NOT EXISTS idx_hubs_handle
53
- ON hubs (handle);
54
- `);
55
-
56
- await knex.raw(`
57
- CREATE INDEX IF NOT EXISTS idx_releases_archived
58
- ON releases (archived);
59
- `);
60
-
61
- await knex.raw(`
62
- CREATE INDEX IF NOT EXISTS idx_releases_datetime
63
- ON releases (datetime);
64
- `);
65
-
66
- await knex.raw(`
67
- CREATE INDEX IF NOT EXISTS idx_posts_datetime
68
- ON posts (datetime);
69
- `);
70
-
71
- // Add composite indexes for common query patterns
72
- await knex.raw(`
73
- CREATE INDEX IF NOT EXISTS idx_releases_archived_datetime
74
- ON releases (archived, datetime);
75
- `);
76
- };
77
-
78
- export const down = async (knex) => {
79
- // Remove all created indexes
80
- await knex.raw(`DROP INDEX IF EXISTS idx_releases_metadata_artist;`);
81
- await knex.raw(`DROP INDEX IF EXISTS idx_releases_metadata_title;`);
82
- await knex.raw(`DROP INDEX IF EXISTS idx_releases_metadata_tags;`);
83
- await knex.raw(`DROP INDEX IF EXISTS idx_releases_metadata_symbol;`);
84
- await knex.raw(`DROP INDEX IF EXISTS idx_hubs_data_displayname;`);
85
- await knex.raw(`DROP INDEX IF EXISTS idx_posts_data_title;`);
86
- await knex.raw(`DROP INDEX IF EXISTS idx_posts_data_description;`);
87
- await knex.raw(`DROP INDEX IF EXISTS idx_accounts_displayname;`);
88
- await knex.raw(`DROP INDEX IF EXISTS idx_accounts_handle;`);
89
- await knex.raw(`DROP INDEX IF EXISTS idx_hubs_handle;`);
90
- await knex.raw(`DROP INDEX IF EXISTS idx_releases_archived;`);
91
- await knex.raw(`DROP INDEX IF EXISTS idx_releases_datetime;`);
92
- await knex.raw(`DROP INDEX IF EXISTS idx_posts_datetime;`);
93
- await knex.raw(`DROP INDEX IF EXISTS idx_releases_archived_datetime;`);
94
- };