Skip to content

Commit 84d278d

Browse files
committed
Tool and initial change to page size
1 parent 76b777c commit 84d278d

File tree

11 files changed

+927
-3
lines changed

11 files changed

+927
-3
lines changed

src/AppInstallerRepositoryCore/Microsoft/SQLiteIndex.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ namespace AppInstaller::Repository::Microsoft
3737
return { filePath, source };
3838
}
3939

40-
SQLiteIndex::SQLiteIndex(const std::string& target, const SQLite::Version& version) : SQLiteStorageBase(target, version)
40+
SQLiteIndex::SQLiteIndex(const std::string& target, const SQLite::Version& version) : SQLiteStorageBase(target, version, 65536)
4141
{
4242
m_dbconn.EnableICU();
4343
m_interface = Schema::CreateISQLiteIndex(version);

src/AppInstallerSharedLib/Public/winget/SQLiteStorageBase.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ namespace AppInstaller::SQLite
3939
static void RenameSQLiteDatabase(const std::filesystem::path& source, const std::filesystem::path& destination, bool overwrite = false);
4040

4141
protected:
42-
SQLiteStorageBase(const std::string& target, const Version& version);
42+
SQLiteStorageBase(const std::string& target, const Version& version, int pageSize = 0);
4343

4444
SQLiteStorageBase(const std::string& filePath, SQLiteStorageBase::OpenDisposition disposition, Utility::ManagedFile&& indexFile);
4545

src/AppInstallerSharedLib/Public/winget/SQLiteWrapper.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,10 @@ namespace AppInstaller::SQLite
264264
// Must be performed outside of a transaction.
265265
bool SetJournalMode(std::string_view mode);
266266

267+
// Sets the page size for a new, empty database.
268+
// Must be called before the first write to take effect.
269+
void SetPageSize(int pageSize);
270+
267271
operator sqlite3* () const { return m_dbconn->Get(); }
268272

269273
protected:

src/AppInstallerSharedLib/SQLiteStorageBase.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,14 @@ namespace AppInstaller::SQLite
156156
m_version = Version::GetSchemaVersion(m_dbconn);
157157
}
158158

159-
SQLiteStorageBase::SQLiteStorageBase(const std::string& target, const Version& version) :
159+
SQLiteStorageBase::SQLiteStorageBase(const std::string& target, const Version& version, int pageSize) :
160160
m_dbconn(SQLite::Connection::Create(target, SQLite::Connection::OpenDisposition::Create))
161161
{
162162
m_version = version;
163+
if (pageSize > 0)
164+
{
165+
m_dbconn.SetPageSize(pageSize);
166+
}
163167
MetadataTable::Create(m_dbconn);
164168

165169
// Write a new identifier for this database

src/AppInstallerSharedLib/SQLiteWrapper.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,15 @@ namespace AppInstaller::SQLite
251251
return ToLower(setJournalMode.GetColumn<std::string>(0)) == ToLower(mode);
252252
}
253253

254+
void Connection::SetPageSize(int pageSize)
255+
{
256+
std::ostringstream stream;
257+
stream << "PRAGMA page_size=" << pageSize;
258+
259+
Statement setPageSize = Statement::Create(*this, stream.str());
260+
setPageSize.Step();
261+
}
262+
254263
std::shared_ptr<details::SharedConnection> Connection::GetSharedConnection() const
255264
{
256265
return m_dbconn;
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project DefaultTargets="Build" ToolsVersion="16.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup Label="ProjectConfigurations">
4+
<ProjectConfiguration Include="Debug|ARM64">
5+
<Configuration>Debug</Configuration>
6+
<Platform>ARM64</Platform>
7+
</ProjectConfiguration>
8+
<ProjectConfiguration Include="Debug|x64">
9+
<Configuration>Debug</Configuration>
10+
<Platform>x64</Platform>
11+
</ProjectConfiguration>
12+
<ProjectConfiguration Include="Release|ARM64">
13+
<Configuration>Release</Configuration>
14+
<Platform>ARM64</Platform>
15+
</ProjectConfiguration>
16+
<ProjectConfiguration Include="Release|x64">
17+
<Configuration>Release</Configuration>
18+
<Platform>x64</Platform>
19+
</ProjectConfiguration>
20+
</ItemGroup>
21+
22+
<PropertyGroup Label="Globals">
23+
<VCProjectVersion>16.0</VCProjectVersion>
24+
<ProjectGuid>{2F8A1C3E-7B4D-4E9F-A6C2-1D5E8B3F0A7C}</ProjectGuid>
25+
<Keyword>Win32Proj</Keyword>
26+
<RootNamespace>IndexComparisonTool</RootNamespace>
27+
<WindowsTargetPlatformVersion>10.0.26100.0</WindowsTargetPlatformVersion>
28+
<WindowsTargetPlatformMinVersion>10.0.17763.0</WindowsTargetPlatformMinVersion>
29+
<WindowsSDKDesktopARM64Support>true</WindowsSDKDesktopARM64Support>
30+
</PropertyGroup>
31+
32+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
33+
34+
<PropertyGroup Label="Configuration">
35+
<ConfigurationType>Application</ConfigurationType>
36+
<CharacterSet>Unicode</CharacterSet>
37+
<PlatformToolset>v143</PlatformToolset>
38+
</PropertyGroup>
39+
<PropertyGroup Condition="'$(Configuration)'=='Debug'" Label="Configuration">
40+
<UseDebugLibraries>true</UseDebugLibraries>
41+
<LinkIncremental>true</LinkIncremental>
42+
</PropertyGroup>
43+
<PropertyGroup Condition="'$(Configuration)'=='Release'" Label="Configuration">
44+
<UseDebugLibraries>false</UseDebugLibraries>
45+
<WholeProgramOptimization>true</WholeProgramOptimization>
46+
<LinkIncremental>false</LinkIncremental>
47+
</PropertyGroup>
48+
49+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
50+
51+
<ImportGroup Label="PropertySheets">
52+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props"
53+
Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')"
54+
Label="LocalAppDataPlatform" />
55+
</ImportGroup>
56+
57+
<PropertyGroup Label="UserMacros" />
58+
59+
<PropertyGroup>
60+
<OutDir>$(ProjectDir)bin\$(Platform)\$(Configuration)\</OutDir>
61+
<IntDir>$(ProjectDir)obj\$(Platform)\$(Configuration)\</IntDir>
62+
</PropertyGroup>
63+
64+
<ItemDefinitionGroup>
65+
<ClCompile>
66+
<PrecompiledHeader>Use</PrecompiledHeader>
67+
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
68+
<PrecompiledHeaderOutputFile>$(IntDir)pch.pch</PrecompiledHeaderOutputFile>
69+
<WarningLevel>Level4</WarningLevel>
70+
<TreatWarningAsError>true</TreatWarningAsError>
71+
<SDLCheck>true</SDLCheck>
72+
<AdditionalOptions>/permissive- /std:c++17 %(AdditionalOptions)</AdditionalOptions>
73+
<!-- WinGetUtil.h is local to this project; no extra include dir needed -->
74+
<PreprocessorDefinitions>UNICODE;_UNICODE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
75+
</ClCompile>
76+
<Link>
77+
<SubSystem>Console</SubSystem>
78+
<!-- Cabinet.lib and winsqlite3.lib are pulled in via #pragma comment(lib) in main.cpp -->
79+
<!-- WinGetUtil.dll is loaded at runtime via LoadLibrary; no import lib needed -->
80+
<AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
81+
</Link>
82+
</ItemDefinitionGroup>
83+
84+
<ItemDefinitionGroup Condition="'$(Configuration)'=='Debug'">
85+
<ClCompile>
86+
<Optimization>Disabled</Optimization>
87+
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
88+
</ClCompile>
89+
</ItemDefinitionGroup>
90+
91+
<ItemDefinitionGroup Condition="'$(Configuration)'=='Release'">
92+
<ClCompile>
93+
<Optimization>MaxSpeed</Optimization>
94+
<FunctionLevelLinking>true</FunctionLevelLinking>
95+
<IntrinsicFunctions>true</IntrinsicFunctions>
96+
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
97+
</ClCompile>
98+
<Link>
99+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
100+
<OptimizeReferences>true</OptimizeReferences>
101+
</Link>
102+
</ItemDefinitionGroup>
103+
104+
<ItemGroup>
105+
<ClInclude Include="pch.h" />
106+
<ClInclude Include="WinGetUtil.h" />
107+
</ItemGroup>
108+
<ItemGroup>
109+
<ClCompile Include="main.cpp" />
110+
<ClCompile Include="pch.cpp">
111+
<PrecompiledHeader>Create</PrecompiledHeader>
112+
</ClCompile>
113+
</ItemGroup>
114+
115+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
116+
</Project>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup>
4+
<Filter Include="Source Files">
5+
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
6+
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
7+
</Filter>
8+
<Filter Include="Header Files">
9+
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
10+
<Extensions>h;hh;hpp;hxx;hm;inl;inc;ipp;xsd</Extensions>
11+
</Filter>
12+
</ItemGroup>
13+
<ItemGroup>
14+
<ClCompile Include="main.cpp">
15+
<Filter>Source Files</Filter>
16+
</ClCompile>
17+
<ClCompile Include="pch.cpp">
18+
<Filter>Source Files</Filter>
19+
</ClCompile>
20+
</ItemGroup>
21+
<ItemGroup>
22+
<ClInclude Include="pch.h">
23+
<Filter>Header Files</Filter>
24+
</ClInclude>
25+
<ClInclude Include="WinGetUtil.h">
26+
<Filter>Header Files</Filter>
27+
</ClInclude>
28+
</ItemGroup>
29+
</Project>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT License.
3+
4+
// Minimal WinGetUtil types and function pointer declarations for use
5+
// with runtime loading via LoadLibrary. Only the APIs used by
6+
// IndexComparisonTool are defined here.
7+
#pragma once
8+
9+
typedef void* WINGET_SQLITE_INDEX_HANDLE;
10+
typedef wchar_t const* WINGET_STRING;
11+
12+
#define WINGET_SQLITE_INDEX_VERSION_LATEST ((UINT32)-1)
13+
14+
typedef HRESULT (__stdcall *PFN_WinGetSQLiteIndexCreate)(
15+
WINGET_STRING filePath,
16+
UINT32 majorVersion,
17+
UINT32 minorVersion,
18+
WINGET_SQLITE_INDEX_HANDLE* index);
19+
20+
typedef HRESULT (__stdcall *PFN_WinGetSQLiteIndexAddManifest)(
21+
WINGET_SQLITE_INDEX_HANDLE index,
22+
WINGET_STRING manifestPath,
23+
WINGET_STRING relativePath);
24+
25+
typedef HRESULT (__stdcall *PFN_WinGetSQLiteIndexPrepareForPackaging)(
26+
WINGET_SQLITE_INDEX_HANDLE index);
27+
28+
typedef HRESULT (__stdcall *PFN_WinGetSQLiteIndexClose)(
29+
WINGET_SQLITE_INDEX_HANDLE index);

0 commit comments

Comments
 (0)